Home >Java >javaTutorial >Java basics (infinite loop exit option)
In order for the program to run normally in a java program, an exit option needs to be added to the infinite loop to ensure the executability of the program.
import java.util.Scanner; public class View Code { public static void main(String[] args) { Scanner scan = new Scanner(System.in); system.out.println("请输入您的操作选项"); int num = scan.nextInt(); switch (num) { case '1': Scanner scan = new Scanner (System.in); System.out.println("请输入用户名:"); int user = scan.nextInt(); System.out.println("请输入密码:"); int password = scan.nextInt(); if(ture&&ture){ System.out.println("登陆成功"); /*继续执行下一步操作*/ }else{ System.out.println("登陆失败,请重新登录"); } case '2': system.exit(-1); default: System.out.println("无效的输入,请 重新输入"); }