Interview Question
Country: United States
Attribute Class:
import java.util.ArrayList;
public class DataList {
public String name;
public String address;
public int age;
public float sal;
}
Main Class:
import java.util.ArrayList;
import java.util.Scanner;
import java.util.Iterator;
public class ArrayofClass {
public static void main(String args[]){
DataList dl=null;
ArrayList<DataList> al = new ArrayList<DataList>();
Scanner sc = new Scanner(System.in);
for(int i=0; i<10; i++){
dl = new DataList();
System.out.println("Enter name, place, age, sal and press enter key after each input");
dl.name = sc.next();
dl.address = sc.next();
dl.age = sc.nextInt();
dl.sal = sc.nextFloat();
al.add(dl);
}
Iterator<DataList> itr = al.iterator();
DataList temp = null;
while(itr.hasNext()){
temp = (DataList)itr.next();
System.out.println(temp.name + " " + temp.address + " " + temp.sal + " " + temp.age);
}
}
}
sc
- cs February 26, 2014