Click here to Skip to main content
15,884,589 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Java
import java.util.Scanner;

public class Employee {
private int marks[]=new int[10];

public int[] getMarks() {
	return marks;
}
public void setMarks(int[] marks) {
	this.marks = marks;
}
}

import java.util.*;

public class MainEmployee
{
public static void main(String args[])
{ 	Scanner sss=new Scanner(System.in);
Employee e1=new Employee();
        System.out.println("enter the no of sub");
	int sub=sss.nextInt();
	int marks[]=new int[10];
System.out.println("Enter marks:");
for(int i=0;i<sub;i++)
{
marks[i]=sss.nextint();
}
e1.setMarks(marks);
 system.out.println("marks are:"+e1.getMarks());

}


What I have tried:

Java
System.out.println("Enter marks:");
for(int i=0;i<sub;i++)
{
marks[i]=sss.nextint();
}
e1.setMarks(marks);
 system.out.println("marks are:"+e1.getMarks());  //Output:Marks are:[I@42a57993

}

I want to print all the marks from user by using gemarks() but I'm getting garbage value. Where I'm going wrong and how to fix this?Any help is appreciated.
Posted
Updated 2-Jul-19 0:45am
v7
Comments
Richard MacCutchan 2-Jul-19 3:20am    
What is the problem? Also please format your code properly.
Member 13954890 2-Jul-19 3:42am    
I want to print all the marks which I got from users by using getMarks() but I'm getting some garbage value. Where I'm wrong and how to fix it?
Richard MacCutchan 2-Jul-19 6:46am    
See below.

1 solution

Java
system.out.println("marks are:"+e1.getMarks());

Your getMarks() method returns an array, rather than something that is printable. The default implementation of an array's toString() method just prints the address of the array. You need to add a method that prints the individual members of the array.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900