当用户未输入与先前输入的号码相同的号码时,创建一个将持续接受号码的程序[重复]

问题描述 投票:-4回答:1

这个问题在这里已有答案:

这是我无法创建的唯一程序。请帮我解决一下这个。

public static void main(String[] args) {
    Scanner input = new Scanner(System.in);
    int i = 0, j=0;
     do {
         System.out.print("Enter number: ");
         i = input.nextInt();

         i=j;
     }

     while (i == j);
     System.out.println("You have inputted the same number on the previous.");

}
java loops
1个回答
0
投票

干杯m8,祝你考试好运:D

  public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int i = 0, j = 999999, input = 0;
         do {
             i = j;
             System.out.print("Enter number: ");
             input = input.nextInt();

             j=input;
         } while (i != j);
         System.out.println("You have inputted the same number on the previous.");

    }
© www.soinside.com 2019 - 2024. All rights reserved.