vendredi 9 octobre 2015

Can I use "return" in here or any ideas?

I'm really new to Java and most of my knowledge are self- taught. can you help me to figure out this.

Our teacher wants us to make a menu about Java. Where the output something like this..

Menu 1 - Java History 2- Java Keywords 3 - Java Arrays and so on. .

Do you want to read one (Yes/No): //if yes

Please enter a menu number: // then it will display an information..

//my problem is that how can I connect the new entered value to the first method so that I don't have write it all over again...

this is whats on my mind.. but im stuck..

import java.util.Scanner;

public class Program {

public static void main (String [] args) {

System.out.println("Please enter a number:");
int x = nextInt();

if (x == 1) {

     for (int x = 5; x == 5;x++) // array of 1(first menu)

System.out.println ("Do you want to read another? (Yes/No):");
System.out.println ("Please enter a menu number:")

// return to if with it's new entered value....

     }
    else if (x == 2)  {
    for loop of array 2

    System.out.println ("Do you want to read another? (Yes/No):");
    System.out.println ("Please enter a menu number:")

    // return to if with it's new entered value....


}   

else if (x == 3) {
    for loop of array 3

    System.out.println ("Do you want to read another? (Yes/No):");
    System.out.println ("Please enter a menu number:")

    // return to if with it's new entered value....


else if (x ==4) { 
    for loop of array 4

else if (x == 5) {
    for loop of array 5

else if (x == 6) {
    for loop of array 6

else if (x == 7) {
    for loop of array 7

else if (x == 8) {
    for loop of array 8

else if (x == 9) {
    for loop of array 9

else if (x == 10) {
    for loop of array 10

 else {
   //exit the program

Aucun commentaire:

Enregistrer un commentaire