结果不一致

时间:2020-05-28 04:58:38

标签: java arrays for-loop

我处理过的代码在100%的时间内无效。我一直让程序尝试为数组中的一个整数创建多个整数。结果是我需要等于num的引脚。当我运行程序时,有时num是要打印的内容,而在其他时候,程序会决定不等于之前打印的内容。

例如,这个结果
引脚:0 1 2 3 4 5 6 7 8 9
编号:2 2 3 2 3 2 3 2 1 3
输入密码 代码是32345
密码应为23232

但是此答案可能有效也可能无效。

import java.util.*;
import java.text.*;
import java.lang.*;
public class Authenticate_TylerD {
public static void main(String[] args){
    Scanner scan = new Scanner (System.in);

    //arrays
    int[] pin = {3, 2, 3, 4, 5};
    int[] num = new int[10];
    int userIn;
    int[] userIn2 = new int [5];

    //Numbers for pin
    System.out.println("Pin: 0 1 2 3 4 5 6 7 8 9");
    System.out.print("Num: ");

    //shou
    for(int i = 0;i<=9;i++){
            num[i] = (int)(Math.random()*3)+1;
            System.out.print(num[i] + " ");
        for(int j=0;j<5;j++){
            if(i == pin[j]){
                pin[j] = num[i];
                //System.out.print(num[i] + "<-- RanNum ");
            }
            else{
                continue;
            }
        }
    }
    System.out.println("\n------------------------------");
    System.out.println("Enter the password");
    userIn = scan.nextInt();

    for(int i = 4;i>=0;i--){
        userIn2[i] = userIn%10;
        userIn = userIn/10;
        System.out.print(pin[i]);
        System.out.print(userIn2[i]);

        if(userIn2[i] != pin[i]){
            System.out.print("\nIncorrect PIN");
            System.exit(0);
        }
        else{
            System.out.print("Correct PIN ");
        }
    }
}
}

任何帮助将不胜感激。附言不必急着回答这个问题,请有机会请回信。

0 个答案:

没有答案
相关问题