java - What I am doing incorrectly when creating a method in a class? -


i trying create program user enters 2d array, , program find highest value in array, , output value, , associated row , column. have created method (called locatelargest) inside class goes through points in 2d array, , sets aside maxvalue. returns maxvalue. errors ) , ] expected, illegal start of type, ; expected, , identifier expected. how can method , program overall work? thank time.

import java.util.scanner;  public class find {  public static void main(string[] args) { scanner input = new scanner(system.in); system.out.print ("enter number of rows in the array: "); int numberofrows = input.nextint(); system.out.print ("enter number of rows in the array: "); int numberofcolumns = input.nextint();  double[][] anarray = new double[numberofrows][numberofcolumns];   system.out.println("enter array: "); (int = 0; < a.length; i++){   (int j = 0; j < a[i].length; j++){     a[i][j] = input.nextdouble();   }   } location location = locatelargest(anarray); system.out.println("the location of largest element "   + location.maxvalue + " @ ("   + location.row + ", " + location.column + ")");        }   }    class location{      public double maxvalue;      public int row;      public int column;          public static double[] locatelargest(double[r][c] array){                (int r = 0; r < array.length; r++){                  (int c = 0; c < array[r].length; c++){                     if (b[row][column] > maxvalue){                        maxvalue = array[row][column];                        row = r;                        column = c;                        return maxvalue;                      }                  }               }         }          } 

update: have program running correctly. here code.

import java.util.scanner;  public class big {  public static void main(string[] args) { scanner input = new scanner(system.in); system.out.print ("enter number of rows in the array: "); int numberofrows = input.nextint(); system.out.print ("enter number of rows in the array: "); int numberofcolumns = input.nextint();  double[][] array = new double[numberofrows][numberofcolumns];   system.out.println("enter array: "); (int = 0; < array.length; i++){   (int j = 0; j < array[i].length; j++){     array[i][j] = input.nextdouble();      }       } location location = new location();  location.locatelargest(array);  system.out.println("the location of largest element "   + location.maxvalue + " @ ("   + location.row + ", " + location.column + ")");          }     }    class location{      public static double maxvalue;      public static int row;      public static int column;          public static double locatelargest(double[][] array){                (int r = 0; r < array.length; r++){                  (int c = 0; c < array[r].length; c++){                     if (array[r][c] > maxvalue){                        maxvalue = array[r][c];                        row = r;                        column = c;                       }                  }               }               return maxvalue;         }          } 

some basic issues started:

your method signature should public static double locatelargest(double[][] array) start. unless trying return array of row , column int[]

you should have

   if (b[r][c] > maxvalue){         maxvalue = array[r][c]; 

you need move return statement outside of loop. need declare double maxvalue (and don't capitalize variable name)

you need call location.locatelargest(array) , method name conventionally locatelargest

tl;dr: sotirios right. need go , read manual.


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -