Write some Java statements to complete the program Declare a
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;
}
}
