【发布时间】:2019-03-28 16:39:33
【问题描述】:
我正在努力正确循环我编写的将整数转换为罗马数字的代码。
我尝试实现一个 do while 循环来运行从“请输入一个整数”开始并在我的 switch 语句之后结束的代码,while 部分是:while(case "y" || "Y" == true ) 任何帮助将不胜感激。我已经搜索了几个小时之前关于堆栈溢出的帖子,但找不到任何有用的东西。
公开课项目8 {
/**
* Constructor for objects of class Project4
*/
public static void main(String[] args) {
System.out.println("Welcome to my integer Roman numeral conversion program");
System.out.println("------------------------------------------------------");
System.out.println(" ");
Scanner in = new Scanner (System.in);
System.out.print("Enter an integer in the range 1-3999 (both inclusive): ");
int input = in.nextInt();
if (input < 0 || input > 3999){
System.out.println("Sorry, this number is outside the range.");
System.out.println("Do you want to try again? Press Y for yes and N for no: ");
String userInput = in.next();
switch (userInput) {
case "N":
case "n":
System.exit(0);
break;
case "Y":
case "y":
break;
}
}
else if (input > 0 && input < 3999);
{ System.out.println(Conversion.Convert(input));
}
}
}
【问题讨论】:
标签: java loops switch-statement