java - Cannot find symbol - when calling a method -
the purpose of code find maximum value in user-inputted 2-dimensional array. code makes sense when seek , compile, gives me next error:
error: locatelargestelement.java:41: error: cannot find symbol int result = maxvalue(usermatrix); ^ symbol: variable usermatrix location: class locatelargestelement 1 errori tried talk programming professor, beingness real mature , not help me. basically, trying create result
maxvalue
, says cannot find usermatrix
.
//import utility import java.util.scanner; //initialize programme public class locatelargestelement { public static void main (string [] args) { scanner input = new scanner(system.in); int userint = 0; { run(input); system.out.println("do want continue? 1 yes, 2 no: "); userint = input.nextint(); } while (userint == 1); } //method run public static void run (scanner input) { int result = maxvalue(usermatrix); //<--- cannot find "usermatrix" error system.out.println("the largest value in given matrix is: " + result); } //method inquire user number of rows public static int lengthrow (scanner input) { system.out.println("please come in number of rows of desired matrix: "); int lengthrow = input.nextint(); homecoming lengthrow; } //method inquire user number of columns public static int lengthcolumn (scanner input) { system.out.println("please come in number of columns of desired matrix: "); int lengthcolumn = input.nextint(); homecoming lengthcolumn; } //method inquire user input of values public static int [][] usermatrix (scanner input, int lengthrow, int lengthcolumn) { int [][] usermatrix = new int [lengthrow][lengthcolumn]; system.out.println("please come in values matrix: "); (int = 0; < lengthrow; i++) { (int j = 0; j < lengthcolumn; j++) { usermatrix[i][j] = input.nextint(); } } homecoming usermatrix; } //method find largest element in matrix public static int maxvalue (int[][] usermatrix) { int maxvalue = 0; (int = 0; < usermatrix.length; i++) { (int j = 0; j < usermatrix[i].length; j++) { if (usermatrix[i][j] > maxvalue) { maxvalue = usermatrix[i][j]; } } } homecoming maxvalue; } }
your first problem have variable , method named same, confuse on usage. isn't technical problem code, problem reading code.
i think intend this. need phone call method , pass arguments requires. since have methods obtaining other values, should gather first. create code function, improve structured.
public static void run (scanner input) { int row = lengthrow(input); int column = lengthcolumn(input); int result = maxvalue(usermatrix(input, row, column)); system.out.println("the largest value in given matrix is: " + result); }
i'll leave exercise reader create better.
java multidimensional-array error-handling cannot-find-symbol
No comments:
Post a Comment