Java 检查输入到数组中的输入是否正确/不正确

Java 检查输入到数组中的输入是否正确/不正确,java,arrays,input,java.util.scanner,Java,Arrays,Input,Java.util.scanner,我正在处理一个问题,其中我必须检查输入到数组中的输入是否在1到10000之间。如果这是真的,我必须继续进行下一组操作。我该怎么办呢。 请在下面找到我的代码: Scanner in = new Scanner(System.in); System.out.println("Enter 10 values between 1 and 10000: " ); for(int i=0; i<10; i++) { if (z[i]>1 &&

我正在处理一个问题,其中我必须检查输入到数组中的输入是否在1到10000之间。如果这是真的,我必须继续进行下一组操作。我该怎么办呢。 请在下面找到我的代码:

Scanner in =  new Scanner(System.in);
    System.out.println("Enter 10 values between 1 and 10000: " );
    for(int i=0; i<10; i++) {
          if (z[i]>1 && z[i]<10000) {
        z[i] = in.nextInt();
        }
    }
Scanner-in=新的扫描仪(System.in);
System.out.println(“输入10个介于1和10000之间的值:”);

对于(int i=0;i1&&z[i],首先将输入保存到变量

int num = in.nextInt();
然后验证

if(num>1 && num < 10000) {
   z[i] =num;
}else {
   System.out.printf("Invalid number: %d",num);
}
if(num>1&&num<10000){
z[i]=num;
}否则{
System.out.printf(“无效编号:%d”,num);
}

首先将输入保存到变量

int num = in.nextInt();
然后验证

if(num>1 && num < 10000) {
   z[i] =num;
}else {
   System.out.printf("Invalid number: %d",num);
}
if(num>1&&num<10000){
z[i]=num;
}否则{
System.out.printf(“无效编号:%d”,num);
}

首先将输入保存到变量

int num = in.nextInt();
然后验证

if(num>1 && num < 10000) {
   z[i] =num;
}else {
   System.out.printf("Invalid number: %d",num);
}
if(num>1&&num<10000){
z[i]=num;
}否则{
System.out.printf(“无效编号:%d”,num);
}

首先将输入保存到变量

int num = in.nextInt();
然后验证

if(num>1 && num < 10000) {
   z[i] =num;
}else {
   System.out.printf("Invalid number: %d",num);
}
if(num>1&&num<10000){
z[i]=num;
}否则{
System.out.printf(“无效编号:%d”,num);
}

您希望使用以下模式行(伪代码,因为此类问题通常是基于家庭作业和学习的,而不是找到答案和副本)。我希望未来有伟大的程序员

首先设置:

Issue the "what you should enter" message
Initialize any needed counters
begin the loop (while counters < value?)
   // use try catch to surround your input and calculations to catch malformed integers etc
   try {
       get candidate data element from input stream
       check for validity
         if success increment count, do other needed work
         if fail, reissue "what you should enter" message or more specific error message
   } catch malformed input {
         reissue "what you shoue enter" message, including error for malformed input
   }
end loop
  • 将一个变量初始化为“您应该输入什么”消息,这是您为用户计划的。为什么?因此,如果您需要更改它,您只有一个地方可以去
  • 将变量初始化为您将检测到的任何错误消息
  • 建立输入流
  • 现在循环:

    Issue the "what you should enter" message
    Initialize any needed counters
    begin the loop (while counters < value?)
       // use try catch to surround your input and calculations to catch malformed integers etc
       try {
           get candidate data element from input stream
           check for validity
             if success increment count, do other needed work
             if fail, reissue "what you should enter" message or more specific error message
       } catch malformed input {
             reissue "what you shoue enter" message, including error for malformed input
       }
    end loop
    
    发出“您应该输入什么”消息
    初始化任何需要的计数器
    开始循环(计数器<值时?)
    //使用try-catch环绕输入和计算以捕获格式错误的整数等
    试一试{
    从输入流中获取候选数据元素
    检查有效性
    如果成功增加计数,则执行其他需要的工作
    如果失败,请重新发出“您应该输入的内容”消息或更具体的错误消息
    }捕获格式错误的输入{
    重新发出“您应该输入的内容”消息,包括输入格式错误
    }
    端环
    

    注意,如果您在某些条件出现之前一直在工作(例如,用户输入QUIT),则使用该条件(第一次设置为false)作为循环终止测试。您希望使用以下模式行(伪代码,因为此类问题通常基于家庭作业和学习,而不是查找答案并复制).我想要未来的优秀程序员

    首先设置:

    Issue the "what you should enter" message
    Initialize any needed counters
    begin the loop (while counters < value?)
       // use try catch to surround your input and calculations to catch malformed integers etc
       try {
           get candidate data element from input stream
           check for validity
             if success increment count, do other needed work
             if fail, reissue "what you should enter" message or more specific error message
       } catch malformed input {
             reissue "what you shoue enter" message, including error for malformed input
       }
    end loop
    
  • 将一个变量初始化为“您应该输入什么”消息,这是您为用户计划的。为什么?因此,如果您需要更改它,您只有一个地方可以去
  • 将变量初始化为您将检测到的任何错误消息
  • 建立输入流
  • 现在循环:

    Issue the "what you should enter" message
    Initialize any needed counters
    begin the loop (while counters < value?)
       // use try catch to surround your input and calculations to catch malformed integers etc
       try {
           get candidate data element from input stream
           check for validity
             if success increment count, do other needed work
             if fail, reissue "what you should enter" message or more specific error message
       } catch malformed input {
             reissue "what you shoue enter" message, including error for malformed input
       }
    end loop
    
    发出“您应该输入什么”消息
    初始化任何需要的计数器
    开始循环(计数器<值时?)
    //使用try-catch环绕输入和计算以捕获格式错误的整数等
    试一试{
    从输入流中获取候选数据元素
    检查有效性
    如果成功增加计数,则执行其他需要的工作
    如果失败,请重新发出“您应该输入的内容”消息或更具体的错误消息
    }捕获格式错误的输入{
    重新发出“您应该输入的内容”消息,包括输入格式错误
    }
    端环
    

    注意,如果您在某些条件出现之前一直在工作(例如,用户输入QUIT),则使用该条件(第一次设置为false)作为循环终止测试。您希望使用以下模式行(伪代码,因为此类问题通常基于家庭作业和学习,而不是查找答案并复制).我想要未来的优秀程序员

    首先设置:

    Issue the "what you should enter" message
    Initialize any needed counters
    begin the loop (while counters < value?)
       // use try catch to surround your input and calculations to catch malformed integers etc
       try {
           get candidate data element from input stream
           check for validity
             if success increment count, do other needed work
             if fail, reissue "what you should enter" message or more specific error message
       } catch malformed input {
             reissue "what you shoue enter" message, including error for malformed input
       }
    end loop
    
  • 将一个变量初始化为“您应该输入什么”消息,这是您为用户计划的。为什么?因此,如果您需要更改它,您只有一个地方可以去
  • 将变量初始化为您将检测到的任何错误消息
  • 建立输入流
  • 现在循环:

    Issue the "what you should enter" message
    Initialize any needed counters
    begin the loop (while counters < value?)
       // use try catch to surround your input and calculations to catch malformed integers etc
       try {
           get candidate data element from input stream
           check for validity
             if success increment count, do other needed work
             if fail, reissue "what you should enter" message or more specific error message
       } catch malformed input {
             reissue "what you shoue enter" message, including error for malformed input
       }
    end loop
    
    发出“您应该输入什么”消息
    初始化任何需要的计数器
    开始循环(计数器<值时?)
    //使用try-catch环绕输入和计算以捕获格式错误的整数等
    试一试{
    从输入流中获取候选数据元素
    检查有效性
    如果成功增加计数,则执行其他需要的工作
    如果失败,请重新发出“您应该输入的内容”消息或更具体的错误消息
    }捕获格式错误的输入{
    重新发出“您应该输入的内容”消息,包括输入格式错误
    }
    端环
    

    注意,如果您在某些条件出现之前一直在工作(例如,用户输入QUIT),则使用该条件(第一次设置为false)作为循环终止测试。您希望使用以下模式行(伪代码,因为此类问题通常基于家庭作业和学习,而不是查找答案并复制).我想要未来的优秀程序员

    首先设置:

    Issue the "what you should enter" message
    Initialize any needed counters
    begin the loop (while counters < value?)
       // use try catch to surround your input and calculations to catch malformed integers etc
       try {
           get candidate data element from input stream
           check for validity
             if success increment count, do other needed work
             if fail, reissue "what you should enter" message or more specific error message
       } catch malformed input {
             reissue "what you shoue enter" message, including error for malformed input
       }
    end loop
    
  • 将一个变量初始化为“您应该输入什么”消息,这是您为用户计划的。为什么?因此,如果您需要更改它,您只有一个地方可以去
  • 将变量初始化为您将检测到的任何错误消息
  • 建立输入流
  • 现在循环:

    Issue the "what you should enter" message
    Initialize any needed counters
    begin the loop (while counters < value?)
       // use try catch to surround your input and calculations to catch malformed integers etc
       try {
           get candidate data element from input stream
           check for validity
             if success increment count, do other needed work
             if fail, reissue "what you should enter" message or more specific error message
       } catch malformed input {
             reissue "what you shoue enter" message, including error for malformed input
       }
    end loop
    
    发出“您应该输入什么”消息
    初始化任何需要的计数器
    开始循环(计数器<值时?)
    //使用try-catch环绕输入和计算以捕获格式错误的整数等
    试一试{
    从输入流中获取候选数据元素
    检查有效性
    如果成功增加计数,则执行其他需要的工作
    如果失败,请重新发出“您应该输入的内容”消息或m