Java帮助重启程序
import java.util.Scanner ; public class Mal { public static void main (String []args) { System.out.println("Welcome") ; Scanner myinput=new Scanner (System.in) ; System.out.println("Make your choice. \n 1.Check a card number \n 2.Quit."); int choise=myinput.nextInt(); switch(choise) { case 1:System.out.println("Enter your credit card number: "); break; case 2:System.out.println("Are you sure?") ; String answer=myinput.next(); if(answer.equals("yes")){ System.out.println("Byee :)") ; System.exit(0); } break; default: System.out.println("Idiot!") ; break; } } }
如果用户键入的内容不同于“是”,我想要一个程序再次启动
这是你能做的
有这样的旗帜
boolean quit = false;
一会儿你的选择
while(!quit){ ... ... }
和
如果用户想要退出,则设置quit = true
。
编辑:
像这样的东西
public static void main(String a[]) { System.out.println("Welcome"); Scanner myinput = new Scanner(System.in); boolean quit = false; while (!quit) { System.out .println("Make your choise. \n 1.Check a card number \n 2.Quit."); int choise = myinput.nextInt(); switch (choise) { case 1: System.out.println("Enter your credit card number: "); break; case 2: System.out.println("Are you sure?"); String answer = myinput.next(); if (answer.equals("yes")) { System.out.println("Byee :)"); quit= true; } break; default: System.out.println("Idiot!"); break; } }
- 无法在自定义Apache Shiro AuthorizingRealm中@Inject我的DAO
- java.lang.NoClassDefFoundError:sun / swing / plaf / synth / SynthUI
- Apache poi日期格式
- 如何以编程方式将AccessLogValve添加到Tomcat?
- 非空字符串的哈希码是否可以为零?
- GetWindowTextA,GetWindowText在Edit Control上返回空值
- 最大化JFrame的行动?
- 有选择地扩展Spring Data Rest响应中的关联
- 如何在JAVA中的HttpURLConnection中发送PUT,DELETE HTTP请求