【发布时间】:2015-10-10 02:13:09
【问题描述】:
我真的是 Java 新手,我的大部分知识都是自学的。你能帮我解决这个问题吗?
我们的老师要我们制作一个关于 Java 的菜单。像这样的输出在哪里..
菜单 1 - Java 历史 2- Java 关键字 3 - Java 数组等。 .
你想读一个吗(是/否): //如果是的话
请输入菜单号: // 然后它会显示一个信息..
//我的问题是如何将新输入的值连接到第一个方法,这样我就不用重新写了...
这是我的想法.. 但我卡住了..
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
【问题讨论】:
-
你需要一个while循环吗?
标签: java if-statement return