Home >Java >javaTutorial >Java basics (infinite loop exit option)

Java basics (infinite loop exit option)

高洛峰
高洛峰Original
2016-11-21 13:41:081687browse

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("无效的输入,请  重新输入");          
                   }


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:How to install jdkNext article:How to install jdk