title: Returning to the main menu of a java program without using method
body: <p>I'm currently a newbie to programming. We were tasked to evaluate if the rows and columns intended for the two matrices are acceptable to perform the addition operation. And if invalid, we would display an appropriate message and repeat the process by asking the user whether to repeat the process or not. If the answer is no, control should be back to the main menu. We weren't allowed to use methods at the moment so I'm quite problematic with this.</p>
  <pre><code>import java.util.Scanner;
  public class matrixTransposition {
  public static void main(String[] args) {
      Scanner src = new Scanner(System.in);
  
      int menu_choice;
      char case_choice;
      char case_choice2;
      boolean menu_repeat = true;
      boolean case_repeat = true;
      boolean check = true;
      boolean inCheck = true;
      int rows_A, columns_A;
      int rows_A2, columns_A2;
  
      int rows_S, columns_S;
      int rows_M, columns_M;
  
  
  do{
          //main menu selection here
      
      
          System.out.print(&quot;\nEnter your choice: &quot;);
          menu_choice = src.next().charAt(0);
  
      
          switch(menu_choice){
              case '1':
              
              do{
                  System.out.println(&quot;-------------------------------------------------&quot;);
                  System.out.println(&quot;\t\tMatrix Addition&quot;);
                  
                  //First Matrix/Array
  
                  System.out.print(&quot;\nFirst Matrix: Please enter number of rows: &quot;); //asks the user to enter number of rows
                  rows_A = src.nextInt(); 
                  
                  System.out.print(&quot;\nFirst Matrix: Please enter number of columns: &quot;); //asks the user to enter number of columns
                  columns_A = src.nextInt();
  
                  int [][] firstMatrix_A = new int [rows_A][columns_A];
                  int [][] secondMatrix_A = new int [rows_A][columns_A]; //declaring the arrays to be used
                  int [][] sumMatrix_A = new int [rows_A][columns_A];
  
                  //asks the user to enter values
                  System.out.println(&quot;\nPlease enter values for first matrix: &quot;);
                  for(int i=0; i&lt;rows_A; i++)
                      for(int j=0; j&lt;columns_A; j++)
                      firstMatrix_A[i][j]=src.nextInt();
  
                  //--------------------------------------------------------------------------------
                  //--------------------------------------------------------------------------------
                  
                  //Second Matrix/Array
                  do{
                      System.out.println(&quot;------------------------------------&quot;);
                      System.out.print(&quot;Second Matrix: Please enter number of rows: &quot;); // asks the user to enter rows
                      rows_A2 = src.nextInt(); 
                      
                      System.out.print(&quot;\nSecond Matrix: Please enter number of columns: &quot;); //asks the user to enter columns
                      columns_A2 = src.nextInt();
  
                      //validating if the 2nd matrix has the same length as the first matrix
                      if(rows_A2 != rows_A || columns_A2 != columns_A){
                          System.out.println(&quot;------------------------------------&quot;);
                          System.out.println(&quot;Error! Input is not the same length as the First Matrix!&quot;);
                          System.out.print(&quot;Do you want to input again? [Y][N]: &quot;);
                          case_choice2 = src.next().charAt(0);
                          
                          switch(case_choice2){
                              case 'Y':
                                  check = true;   //if the user entered Y, the user would be able  
                                  break;          //re-enter rows and columns for the 2nd matrix
                              case 'N':
                                  check = false;          //if the user entered N, the user would be immediately brought
                                  menu_repeat = true;      //back to the main menu selection
                                  break;
                              case 'y':
                                  check = true;       //if the user entered Y, the user would be able
                                  break;              //re-enter rows and columns for the 2nd matrix
                              case 'n':
                                  menu_repeat = true;     //if the user entered N, the user would be immediately brought
                                  check = false;          //back to the main menu selection
                                  break;      
                              default:                    //if the user did not enter Y or N, the user would be ask to
                                                          //enter again.
                                  System.out.println(&quot;---------------------------------------------&quot;);
                                  System.out.println(&quot;Invalid Input Please Try Again....&quot;);
              
                              while(case_repeat){
                                  System.out.println(&quot;---------------------------------------------&quot;);
                                  System.out.print(&quot;Try Again? [Y][N]: &quot;);
                                  case_choice2 = src.next().charAt(0);
              
                                  switch(case_choice2){
                                      case 'Y':
                                          check = true;               //if the user entered Y, the user would be able 
                                          case_repeat = false;        //re-enter rows and columns for the 2nd matrix
                                          break;
                                      case 'N':
                                          check = false;               //if the user entered N, the user would be immediately brought
                                          case_repeat = false;         //back to the main menu selection
                                          menu_repeat = true;
                                          break;
                                      case 'y':
                                          check = true;                //if the user entered y, the user would be able
                                          case_repeat = false;          //re-enter rows and columns for the 2nd matrix
                                          break;
                                      case 'n':
                                          check = false;              //if the user entered n, the user would be immediately brought
                                          case_repeat = false;        //back to the main menu selection
                                          menu_repeat = true;
                                          break;
                                      default:                        //if the user did not enter Y or N, the user would be ask to
                                                                      //enter again.
                                          System.out.println(&quot;---------------------------------------------&quot;);
                                          System.out.println(&quot;Invalid Input Please Try Again....&quot;);
                                          case_repeat = true;
                                  }
                              }
                          }      
                      }
                          //else if all inputs are valid the program would proceed to the next step
                      else{
                      
                      //asks the user to enter values
                      System.out.println(&quot;\nPlease enter values for second matrix: &quot;);
                      for(int i=0; i&lt;rows_A2; i++)
                          for(int j=0; j&lt;columns_A2; j++)
                              secondMatrix_A[i][j]=src.nextInt();
                              check = false;
                      }
                  }while(check);
              
                  //--------------------------------------------------------------------------------
                  //--------------------------------------------------------------------------------
  
                  for(int i=0; i&lt;rows_A; i++)
                  for(int j=0; j&lt;columns_A; j++)
                  sumMatrix_A[i][j] = firstMatrix_A[i][j] + secondMatrix_A[i][j]; //adds the two matrices
  
                  System.out.println(&quot;------------------------------------&quot;);     //displays the first matrix
                  System.out.println(&quot;First Matrix&quot;);
                  for(int i=0; i&lt;rows_A; i++){
                      for(int j=0; j&lt;columns_A; j++){
                          System.out.print(firstMatrix_A[i][j] + &quot;  &quot;);    
                      }
                      System.out.println();
                  }
  
                  System.out.println(&quot;------------------------------------&quot;);     //displays the second matrix
                  System.out.println(&quot;Second Matrix&quot;);
                  for(int x=0; x&lt;rows_A2; x++){
                      for(int y=0; y&lt;columns_A2; y++){
                          System.out.print(secondMatrix_A[x][y] + &quot;  &quot;);    
                      }
                      System.out.println();
                  }
  
                  System.out.println(&quot;------------------------------------&quot;);     //displays the sum of the two matrices
                  System.out.println(&quot;Matrix Sum&quot;);
                  for(int i=0; i&lt;rows_A; i++){
                      for(int j=0; j&lt;columns_A; j++){
                          System.out.print(sumMatrix_A[i][j] + &quot;  &quot;);    
                      }
                      System.out.println();
                  }
                  
                  System.out.print(&quot;Do you want to try again? [Y][N]: &quot;);         //asks the user to re-run the operation
                  case_choice = src.next().charAt(0);
              }while(case_choice == 'Y' || case_choice == 'y');                   //if yes the operation would re-run
              
              if(case_choice == 'N' || case_choice == 'n'){                       //if no, the user would be brought back to the
                  menu_repeat = true;                                             //main menu selection
              }
          
              break;
               }
  
            }while(menu_repeat); 
         }
        }  
  </code></pre>