Hi.. im new to java and im writing a code in which i have to show a main menu with matrices addition amd multiplication.. i have almost com[leted it.. but i dont know how to show the option of "MENU AGIAN yes/no"?? what could be the code of it.. cod is:
import java.util.*;

class Case {
import java.util.*;
class Case {
public static void main (String args[ ]) {
Scanner input= new Scanner (System.in);
int x;
char ch;
    System.out.println();
    System.out.println("\n");
    System.out.println(" ***        ***   ");
    System.out.println(" ** **   **  **   ");
    System.out.println(" **  ** **   ** AIN");
    System.out.println(" **    *     ** ENU");
    System.out.println(" **          **    ");
    System.out.println("\n");
    System.out.println("1.MATRIX FOR ADDITION ");
    System.out.println("2.MATRIX FOR MULTIPLICATION ");
    System.out.println("3. EXIT.");
    System.out.println("\n");
    System.out.println("ENTER A NUMBER BETWEEN 1-3");
    x=input.nextInt();
    System.out.println("\n");
    switch(x)
    {
     case 1:
        { 
           System.out.println("ADDITION");
        } break;
     case 2:
        {

           System.out.println("multiplication");
        } break;
     case 3:
      {
       System.out.println("\n");
       System.out.println("Allah Hafiz");
       System.exit(0);

       } break;
    }
     System.out.println("\n");
     //System.out.println("WANT MENU AGAIN?? y/n");


 }
}

use an if statement, and pack the entire 'to loop' within a while loop.

boolean test = true;
while ( test) {
// ...
System.out.println("WANT MENU AGAIN?? Y/N");
char c = readFirstChar(); // replace this by the correct call for
// this. read a String and extract the first char.
test = ... // give test a new value, based on the value of c.
// a simple if statement 'll do the trick.
}

** Here's Your Modified Code **

 import java.util.*;
 import java.io.*;    
 class Case {
 public static void main (String args[ ])throws Exception {
 Scanner input= new Scanner (System.in);
 BufferedReader br =new BufferedReader(newInputStreamReader(System.in));
 int x;
 char ch;
 do
   {
    System.out.println();
    System.out.println("\n");
    System.out.println(" ***      *** ");
    System.out.println(" ** **  ** ** ");
    System.out.println(" ** ** **  ** AIN");
    System.out.println(" **   *    ** ENU");
    System.out.println(" **        ** ");
    System.out.println("\n");
    System.out.println("1.MATRIX FOR ADDITION ");
    System.out.println("2.MATRIX FOR MULTIPLICATION ");
    System.out.println("3. EXIT.");
    System.out.println("\n");
    System.out.println("ENTER A NUMBER BETWEEN 1-3");
    x=input.nextInt();
    System.out.println("\n");
    switch(x)
      {
        case 1:
        {
        System.out.println("ADDITION");
        } break;
        case 2:
        {
        System.out.println("multiplication");
        } break;
        case 3:
        {
        System.out.println("\n");
        System.out.println("Allah Hafiz");
        System.exit(0);
        } break;
        }
        System.out.println("\n");
        System.out.println("Want Menu Again Y/N");
        ch = (char)br.read();
        }
        while(ch!='n'||ch=='N');
        }
        }

What i have done is just created a new object of bufferedReader and accepted a character form user and accordingly used a while loop which will execute until you enter n or N

"Mark this thread as solved if you got your answer Thank You and Keep Coding"

Well it's a package provided by java's SDk that comes with java virtual machine, it's used when one needs to perform input or output operations in their program.(Example taking value or input from console)

But it doesn't mean that this package is limited for input or output functionality only it's having number of classes and interfaces for many other different operations.

If you want to explore more information about java packages you should take a look in following directory
"C:\Program Files\Java\jdk1.7.0_03"(It's a path where you've installed your java SDK)
Open an archieve named "src" in which you will get packages like java,javax, etc now open java and you will get some important packages inside it like "io,lang,math,util,applet,awt etc".Now open "io" package, and inside there you will find some classes and interfaces like

  • BufferedInputStream.java
  • BufferedOutputStream.java
  • BufferedReader.java
  • BufferedWriter.java
  • Console.java
  • DataInputStream.java.............................., etc.

Example:

  • I used BufferedReader class over here for taking a character from console using read() function.

  • And you used Scanner class from package util to take an integer value through console.

"Hope this Helped,Thank You and Keep Coding"

Anurag: it's a good thing you are helping, but try not to spoonfeed. just show/explain the concept, and give them time to think it over.

you are absolutely right @stultuske.. but actually i have few concepts about java (as it seems from my coding as well) and being a student i need to learn more about it.. so what you and @anurag taught were immensely helpful.

This question has already been answered. Start a new discussion instead.