user2956231 user2956231 - 1 year ago 78
Java Question

How to use array from one method in another?

I find problem to use array form one method in another method.

In first method I take input from user and saved data to two arrays.

In second method I have to shows these information from array.

import java.util.Scanner;

public class MarkCalculator {

public static void main(String[] args) {
// TODO Auto-generated method stub

public static void computeMark ()

Scanner exam = new Scanner (;
Scanner coursework = new Scanner (;

int num = 12;
int[] exam_grade = new int[num];
int[] coursework_grade = new int[num];

for (int i=0+1; i<3; i++){

System.out.printf(i+". Modelue"+" Enter grade of exam:");

System.out.printf(i+". Modelue"+" Enter grade of coursework:");

System.out.println("Your grades are: ");


public static void computeResult (int[] coursework_grade, int[] exam_grade)

for (int i = 0+1; i<3; i++) {

System.out.println(i+". Module: "+ "Exam: "+exam_grade[i]+" Coursework: "+coursework_grade[i]);




The problem is, I have no idea how to pass information from array to the second method. I couldn't find any solution. Can someone help me pls?


Answer Source

this is all it takes.


you can pass an array or any object to a method as you would do with a primitive type. But remember when passing an object if the object's state is changed in the called method it gets reflected in the object itself and all references of the object would contain the affected object.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download