• Status: Open
  • Priority: Low
  • Security: Public
  • Views: 23
  • Last Modified:

Sending information from one method to another

Here's what I'm trying to do and I'll explain it as best as I can.

1. input a number that represents the total number of students (Done)
2. take that number, send it to the "enterGrade" method (NOT DONE)

In my code below the "enterGrade" portion i'm stuck at is represented by <<<<<<<<<<<<<<<<<<<<<<<

Any suggestions and help are appreciated.

public static void main(String[] args) {
            Scanner input = new Scanner(System.in);
            //enter student amount
            System.out.println("Enter number of students: ");
            int student = input.nextInt();
            //check if more than 25 students
            if (student > 25) {
                  System.out.println("Cannot have more than 25 students, try again.");
                //Send number of students to enter grade method <<<<<<<<<<<<<<<<<<<<<<<<<<<<<
            int grade = enterGrade(int[] student);
      public static void enterGrade(int[] student) {
            Scanner input = new Scanner(System.in);
            System.out.println("Enter student's grades");
            int grades = 0;
            while( grades < student.length) {
                  student[grades] = input.nextInt();
      public static void studentName() {
Grant Richards
Grant Richards
1 Comment
The first problem is in your main method. Student is an int (i.e. a single number <= 25) and you're trying to pass it as an int array to be populated with grades. You need to create the int array object first (e.g. int[] students = new int[student]), then pass it to the enterGrade method. There is no need to enter the object type, just pass the object itself. You will however need to define the type being passed in to the  enterGrade method when you create it. Hope it helps get you started.

Join & Write a Comment

Featured Post

7 new features that'll make your work life better

It’s our mission to create a product that solves the huge challenges you face at work every day. In case you missed it, here are 7 delightful things we've added recently to monday to make it even more awesome.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now