Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

personld: int

personName: String
personAddress: String

Youhave been given the task to store the values in


the array and print it on the screen.

Input pattern
1st line states the number of
make. object you need to
From 2nd line you willget the data
print on the screen. that you need to
Consider thefollowing input and
better clarity for the output for the
application
cs iON Digital Learning X Content Player | Content MI HackerRank Question - Store

081

Translate unit-3 QB - Goog... ) Java-Solutions-T.. ) Java-Solutions-T.. localhost / localho...

Language Java 15 OEnvironment G Autocomplete Ready


1 fimport java.io.*;
2 import java.util. *;
3 import java . text.*;
4 import java.math. *;
5 import java.util.regex.*
6

7vpublic class Solution {


8V public static void main(String args []) throws Exception {
Scanner sc = new Scanner(System. in);
10 int n= sc.nextInt );
11 Person]p = new Person[n];
12 V for (int i=0;i<n;it+){
13 int personId=Sc.nextInt() ;sc.nextLine();
14
String personName-sc.nextLine (0:
15
String personAddress-sc.nextLine();
16
p[i]=new Person (personId,personName, personAddress);
17 }
18 V for( Person per : p){
19
System. out.println( per.personId);
20
System. out. println( per,personName);
21
System. out . println( per.personAddress);
22
23
24
25
26 ~ lass Person{
27
int personId;
28
String personName;
29
String personAddress;

Line
Test Results
Custom Input Run Code Run Tests
ent G Autocomplete Ready

Id, personName , personAddress) ;

er.personId) ;
er.personName);
er.personAddress);

tring personName, String personAdd ress){

ame;
onAddress;

e){

ress () {
Language Java 15

1 import java.io,*;
1. Store values in the array 2 import java.util. *;
3 import java.text.*;
Consider the following class example with its 4 import java.math.*;
attributes 5 import java.util.reg
Class Person 6
personld: int
7 Vpublic class Solutic
personName: String 8 V public static v
personAddress: String 9 Scanner sc
10 int n= SC.
You have been given the task to store the values in
the array and print it on the screen.
11 Person[Up
12 V for(int i=
Input pattern
1st line states the number of object you need to
make. Test Results Cus
From 2nd line you willget the data that youneed to
print on the screen.
Consider the following input and output for the Compiled successful
better clarity for the application

Sample input: Test case 0


3
1
sahil Test case1A
Add1
2
Sid G Test case 2 A
Add2
3
Dave Test case 3
Add3

Sample output:
1
siON Digital Learning X 9 Content Player | Content M HackerRank Question - Store X

81

Translate Aunit-3 QB - Googl.. Java-Solutions-T.. Java-Solutions-T... AA localhost / localho..


anguage Java 15 Environment G Autocomplete Ready
import java.io, *;
2 import java .util.*;
3 import java.text. *;
import java.math. *;
5 import java.util.regex. *;
6

7V public class Solution {


8 V
public static void main(String args [])
9 throws Exception {
Scanner sc = new Scanner (System. in);
10
int n= SC.nextInt();
11
Person []p = new Person [n];
12 V
for (int i=0;i<n;it+) {
13
int personId=sc.nextInt() ;sc.nextLine();
14
String
15
String
personName=sc.nextLine (); 1
16 personAddress=sc. nextLine ();
p[i]=new Person (personId , personName,
17
18 V
personAddress);
for( Person per : p){
19
System. out. println(
20
System. out.println( per.personId);
21
per.personName);
System.out. println( per.personAddress)
22 ;
22
24
25
26 ~class Person{
27
int personId;
28
29
String personName;
String personAddress;

Test Results Line: 1 Col: 1


Custom Input Run Code Run Tests Submit

You might also like