

Hi Friend,
Try the following code:
import java.util.*;
class ArrayExample3
{
public static void main(String[] args)
{
int sum=0;
Scanner input=new Scanner(System.in);
int[][] array = new int[3][3];
System.out.println("Enter elements for Array : ");
for (int i=0 ; i < array.length ; i++){
for (int j=0 ; j < array[i].length ; j++){
array[i][j] = input.nextInt();
}
}
System.out.print("Enter Key(SEBARIS or BERBARIS): ");
String str=input.next();
if(str.equals("SEBARIS")){
for (int i=0 ; i < array.length ; i++){
for (int j=0 ; j < array[i].length ; j++){
System.out.print(array[i][j]+" ");
sum+=array[i][j];
}
}
System.out.println();
System.out.println(sum);
}
else if(str.equals("BERBARIS")){
for (int i=0 ; i < array.length ; i++){
System.out.println();
for (int j=0 ; j < array[i].length ; j++){
System.out.print(array[i][j]+" ");
sum+=array[i][j];
}
}
System.out.println();
System.out.println(sum/9);
}
else{
System.out.println("No Choice");
}
}
}
Thanks
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.