i have problem with printing the array after reading it. After printing, the address of memory is printed, not value of the array. What can i do for that ?
public class MyClass
{
Student St = new Student();
Student[]Array1 = new Student[10];
void AddList()
{
Scanner Scan = new Scanner(System.in);
for (int i=0; i<Array1.length & i<ArrayF1.length; i++)
{
System.out.println("Enter Student NAME Number " + (i+1) + ":");
Array1[i] = new Student();
Array1[i].setName(Scan.next());
//System.out.println("Enter Student MARK Number " + (i+1) + ":");
//St.setMark(Scan.nextFloat());
}
}
this is my print method. The result of print is like this
(studentproject.Student@1a758cb)
void PrintList()
{
for (int i=0; i<Array1.length; i++)
{
System.out.println(Array1[i]);
}
}
this is my Student Class that i have all my setter and getter method on that … So i have 3 Class how can i work with this 3 class and in one of them get the data and in another print the Mark data and in third class print the Student Name data … how can i do that … i do some code but i dont know is it correct or not … thanks for your help …
public class Student
{
private String Name;
private float Mark;
/**
* @return the Name
*/
public String getName() {
return Name;
}
/**
* @param Name the Name to set
*/
public void setName(String Name) {
this.Name = Name;
}
/**
* @return the Mark
*/
public float getMark() {
return Mark;
}
/**
* @param Mark the Mark to set
*/
public void setMark(float Mark) {
this.Mark = Mark;
}
}
Just override the
toString()method inStudentclass, and return the appropriate string you want to get printed when you print an instance.It may look like: –
Currently, the default implementation of
toString()method ofObjectclass is invoked, and what you are seeing is the format returned from that method, which is of the form –Type@hashCode