Click here to Skip to main content
14,639,056 members
Rate this:
Please Sign up or sign in to vote.
See more:
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:

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

Rate this:
Please Sign up or sign in to vote.

Solution 1

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.
   

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100