Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/apache-spark/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
java while循环帮助提示用户_Java_While Loop - Fatal编程技术网

java while循环帮助提示用户

java while循环帮助提示用户,java,while-loop,Java,While Loop,我正在为我的班级写一个作业,作业内容是:一个SIN数是否有效。我做了所有的数学运算,但我需要帮助做输出。我需要输出说明SIN号是否有效,但如果它有效或无效,它应该在检查SIN号是否有效后重复要求用户再次输入SIN号,并且应该检查它是否有效。有人能帮我一下吗,它可以在while循环中,也可以在for循环或if语句中 这就是我目前得到的 while(total!=999999999) { if(n9==totalA) System.out.println("Th

我正在为我的班级写一个作业,作业内容是:一个SIN数是否有效。我做了所有的数学运算,但我需要帮助做输出。我需要输出说明SIN号是否有效,但如果它有效或无效,它应该在检查SIN号是否有效后重复要求用户再次输入SIN号,并且应该检查它是否有效。有人能帮我一下吗,它可以在while循环中,也可以在for循环或if语句中


这就是我目前得到的

 while(total!=999999999)
    {
      if(n9==totalA)
        System.out.println("The SIN " + total + " is valid.");
      else
        System.out.println("The SIN is not valid");

    }
    while(total!=999999999)
    {
       System.out.println("Please enter your 9 digit Social Insurance Number");
       total = In.getInt();
    if(totalA==n9)
      System.out.println("The SIN " + total + " is valid.");
    else
      System.out.println("The SIN is not valid");

    }

我只需要它让用户重新输入9位数的sin号码,并检查其是否有效,如果我输入99999999,它将停止循环。

由于到目前为止您没有发布任何关于您所做工作的示例代码,我将给您一些伪代码,以便您可以自己找出它

while true
    read sin number
    if sin is valid
        print sin number
    else
         continue

您可以使用一个无限循环,如下面的循环,当SIN有效时,它会打断循环:

while(true)
{
    System.out.println("Enter SIN number");
    //Get input
    if(/*If valid*/)
        break;
    else
        System.out.println("Invalid input.")
}

如果您想要9位SIN,请使用while循环

//this is your input
String sin;
//you can do infinite loop
while(true){

//ask SIN here

   if(sin.length() <9){
     System.out.println("invalid SIN");
   }else{
     //if valid SIN
     break;
   }
}

这就是我目前得到的

 while(total!=999999999)
    {
      if(n9==totalA)
        System.out.println("The SIN " + total + " is valid.");
      else
        System.out.println("The SIN is not valid");

    }
    while(total!=999999999)
    {
       System.out.println("Please enter your 9 digit Social Insurance Number");
       total = In.getInt();
    if(totalA==n9)
      System.out.println("The SIN " + total + " is valid.");
    else
      System.out.println("The SIN is not valid");

    }

现在发生的事情是,如果我输入的第一个sin无效,它会说它无效,但当它再次请求时,我输入一个有效sin,它会说无效???

到目前为止你做了什么?发布一些相关代码。我们不会为您生成代码。