Wednesday, 14 October 2015

Array example in java


public class First {

public static void main(String[] args) {
// TODO Auto-generated method stub
Employee array[] = new Employee[5];
for(int i=0;i<5;i++){
array[i]=new Employee(i,"Sai"+i);
System.out.println("The array values are " +array[i].age +"\t" +array[i].name );
}
}

}



public class Employee {
int age;
String name;
Employee(int i,String s){
age=i;
name=s;
}
}


output:-
The array values are 0 Sai0
The array values are 1 Sai1
The array values are 2 Sai2
The array values are 3 Sai3
The array values are 4 Sai4

No comments:

Post a Comment