I wrote a program that uses an array and Scanner to enter the data of 5 students by using for loop
i didn't have any errors but the output is something like "Student@1d58aae" i think i have problem with adding objects into my array .. i tried ArrayList but i had the same out put
here is my code, using array (i have another one using ArrayList)
import java.util.*;
public class StudentArray2 {
public StudentArray2() {
}
public static void main(String[] args) {
// TODO code application logic here
Scanner k1=new Scanner(System.in);
Student[] a1=new Student[5];
String x;
String y;
double z;
for(int i=0;i<5;i++)
{
System.out.println("Enter the name: ");
x=k1.next();
System.out.println("Enter the ID : ");
y=k1.next();
System.out.println("Enter the GPA: ");
z=k1.nextDouble();
Student s1=new Student(x,y,z);
a1[i]=new Student(x,y,z);
}
for(int i=0;i<5;i++)
System.out.println("the Name is " + a1[i] );
}
}

New Topic/Question
Reply



MultiQuote




|