Write some Java statements to complete the program Declare a

Write some Java statements to complete the program: Declare a 2-D array with the following initial value Invoke the findMax method passing the 2-D array to the method Print out the result of findMax method public class Test {public static void main(String[] args) {//declare the 2-D array with initial values//invoke findMax method and print its result Fill in the code in findMax method that find the maximum value in the elements of the incoming 2-D array argument, and return the result. Public static int finMax (int[][] data) {}} Given the UML diagram shown below, please write Java codes for the class diagram in the left. Account balance: double Name: string + getName(); string +setBalance(balance: double): void

Solution

public class Test {
public static void main(String[] args) {
   int data[][] = new int[][]{{3,2,4},{6,9,7}};        // initialize the two dimensional array
    int max = findMax(data);                           // find the max
    System.out.println(max);
}
public static int findMax(int[][] data){
   int max = data[0][0];                               // get first element
   for(int i=0;i<data.length;i++){                       // loop through each row
       for(int j=0;j<data[i].length;j++){               // loop through each column
           if(data[i][j]>max)                           // check if it greater than max and replace if successful
               max = data[i][j];
       }
   }
   return max;
}
}

/* sample output

9

*/

4)

public class Account {
public double balance;
public String Name;
public String getName(){
   return Name;
}
public void setBalance(double balance){
   this.balance = balance;
}
}

 Write some Java statements to complete the program: Declare a 2-D array with the following initial value Invoke the findMax method passing the 2-D array to the

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site