Methods and arrays in java -
how pass array method can use method in switch
statement in method?
package assignment8exam; import java.util.scanner; /** * * @author anders */ public class course { scanner sc = new scanner(system.in); public void mainmenu() { system.out.println("enter data studen, start entering how many"); int numbers = sc.nextint();// amount of student (int = 0; < numbers; i++) { system.out.println("enter name of student"); scanner name = new scanner(system.in); string names = name.nextline(); string studentnames[] = new string[numbers]; } (int j = 0; j < numbers; j++) { system.out.println("enter grade of student"); scanner gradesc = new scanner(system.in); int grade = gradesc.nextint(); int studentgrade[] = new int[numbers]; } system.out.println("what want"); system.out.println("exit application 1"); system.out.println("print out names of students 2"); system.out.println("print out grades of students 3"); system.out.println("print out pairs consisting of “namegrade 4"); scanner choice = new scanner(system.in); int order = choice.nextint(); switch (order) { case 1: system.exit(1); case 2: printoutnames(numbers); /* can use 1 studentname array*/ } } public void printoutnames(int numbers) { (int = 0; < numbers; i++) { system.out.println(studentnames[i].length); // how activate array studentnames?? } } }
unless i'm missing big, arn't ever setting studentname array new array every time.
string studentnames[] = new string[numbers];
your setting blank array each time.
Comments
Post a Comment