java - Can I use "return" in here or any ideas? -
i'm new java , of knowledge self- taught. can me figure out this.
our teacher wants make menu java. output this..
menu 1 - java history 2- java keywords 3 - java arrays , on. .
do want read 1 (yes/no): //if yes
please enter menu number: // display information..
//my problem how can connect new entered value first method don't have write on again...
this whats on mind.. im stuck..
import java.util.scanner; public class program { public static void main (string [] args) { system.out.println("please enter number:"); int x = nextint(); if (x == 1) { (int x = 5; x == 5;x++) // array of 1(first menu) system.out.println ("do want read another? (yes/no):"); system.out.println ("please enter menu number:") // return if it's new entered value.... } else if (x == 2) { loop of array 2 system.out.println ("do want read another? (yes/no):"); system.out.println ("please enter menu number:") // return if it's new entered value.... } else if (x == 3) { loop of array 3 system.out.println ("do want read another? (yes/no):"); system.out.println ("please enter menu number:") // return if it's new entered value.... else if (x ==4) { loop of array 4 else if (x == 5) { loop of array 5 else if (x == 6) { loop of array 6 else if (x == 7) { loop of array 7 else if (x == 8) { loop of array 8 else if (x == 9) { loop of array 9 else if (x == 10) { loop of array 10 else { //exit program
if understand correctly, want implement while or while statement in program. example of while , while loops
im not sure trying accomplish program here little example made of how utilize loop in case. `import java.util.scanner;
public class main { public static void main(string[] args) { scanner scan = new scanner(system.in); boolean keepgoing = true; //as long true while statement continue; while (keepgoing) { system.out.println("enter number"); int x = scan.nextint(); //logic if (x == 1) { system.out.println("x equal 1"); } else if (x == 2) system.out.println("x equal 2"); //prompts user if want keep going. system.out.println("would keep going? y/n"); string decision = scan.next(); if (decision.equalsignorecase("y")) { keepgoing = true; } else { system.out.println("quitting..."); keepgoing = false; } } } } `
Comments
Post a Comment