Switch statement inside a nested loop. Dealing with multi dimensional array
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner input = new Scanner(System.in); int x[][] = { {1, 3, 5, 7, 9}, {2, 4, 6, 8, 0}, {12, 23, 34, 45, 56} }; for (int i = 0; i <= 2; i++) { for (int j = 0; j <= 4; j++) { switch (i) { case 0: System.out.print(x[i][j] + "\t"); if (j == 4) { System.out.println(); } break; case 1: System.out.print(x[i][j] + "\t"); if (j == 4) { System.out.println(); } break; }//endSwitch } }//end i int a[] = new int[2]; System.out.print("\nColumn (Horizontal): "); a[0] = input.nextInt(); System.out.print("Row (Vertical): "); a[1] = input.nextInt(); System.out.println("Number: " + x[a[0]][a[1]]); } } Can someone explain on why does every time i remove the "break" on case's body, the output will be doubled? Like, if i remove the break in "case 0" the out put will be 1 1 3 3 5 5 7 7 9 9 instead of 1 3 5 7 9. thank you.