java中的中断文件txt

java中的中断文件txt,java,loops,io,break,Java,Loops,Io,Break,我在记事本中的数据 1,2,3,4,5,6,7,8,9,10…为什么当str==5使用中断不起作用时,我的数据应该在数字5中停止…只显示1,2,3,4,5,6,7,8,9,10… Scanner sc = new Scanner (new File("c:/Users/ASUS/Desktop/Numbers.txt")); while (sc.hasNextInt()){ int str = sc.nextInt();

我在记事本中的数据
1,2,3,4,5,6,7,8,9,10…
为什么当
str==5
使用中断不起作用时,我的数据应该在数字5中停止…只显示
1,2,3,4,5,6,7,8,9,10…

 Scanner sc = new Scanner (new File("c:/Users/ASUS/Desktop/Numbers.txt"));
            while (sc.hasNextInt()){
                int str = sc.nextInt();
                for (int i=0; i<str; i++){
                    if (str == 5);
                    break;
                }

                System.out.print(str+ " ");
            }       
            sc.close();
        }
    }
Scanner sc=新扫描仪(新文件(“c:/Users/ASUS/Desktop/Numbers.txt”);
while(sc.hasnetint()){
int str=sc.nextInt();

对于(inti=0;i您需要去掉;after
if(str==5);
应该没有

for (int i=0; i<str; i++){
    if (str == 5)
    {
        break;
    }
}

您需要去掉;after
if(str==5);
应该没有

for (int i=0; i<str; i++){
    if (str == 5)
    {
        break;
    }
}

您需要去掉;after
if(str==5);
应该没有

for (int i=0; i<str; i++){
    if (str == 5)
    {
        break;
    }
}

您需要去掉;after
if(str==5);
应该没有

for (int i=0; i<str; i++){
    if (str == 5)
    {
        break;
    }
}

您可以将代码更改为更简单,并执行以下操作:

 Scanner sc = new Scanner (new File("c:/Users/ASUS/Desktop/Numbers.txt"));
            int str = sc.nextInt();
            while (sc.hasNextInt() && str != 6){
                System.out.print(str+ " ");
                str = sc.nextInt();
            }       
            sc.close();
        }
    }

您可以将代码更改为更简单,并执行以下操作:

 Scanner sc = new Scanner (new File("c:/Users/ASUS/Desktop/Numbers.txt"));
            int str = sc.nextInt();
            while (sc.hasNextInt() && str != 6){
                System.out.print(str+ " ");
                str = sc.nextInt();
            }       
            sc.close();
        }
    }

您可以将代码更改为更简单,并执行以下操作:

 Scanner sc = new Scanner (new File("c:/Users/ASUS/Desktop/Numbers.txt"));
            int str = sc.nextInt();
            while (sc.hasNextInt() && str != 6){
                System.out.print(str+ " ");
                str = sc.nextInt();
            }       
            sc.close();
        }
    }

您可以将代码更改为更简单,并执行以下操作:

 Scanner sc = new Scanner (new File("c:/Users/ASUS/Desktop/Numbers.txt"));
            int str = sc.nextInt();
            while (sc.hasNextInt() && str != 6){
                System.out.print(str+ " ");
                str = sc.nextInt();
            }       
            sc.close();
        }
    }

作为示例的回应,if后面的
结束if语句。使用大括号
{}

if(str==5){
    break;
}
因此:


另一种方法是加载整行,在
上拆分,然后遍历下面的数组,如果有5,则打印出来,如果发现它,则打印出来,只需用示例响应,在if结束if语句后,使用大括号
{}

if(str==5){
    break;
}
因此:


另一种方法是加载整行,在
上拆分,然后遍历下面的数组,如果有5,则打印出来,如果发现它,则打印出来,只需用示例响应,在if结束if语句后,使用大括号
{}

if(str==5){
    break;
}
因此:


另一种方法是加载整行,在
上拆分,然后遍历下面的数组,如果有5,则打印出来,如果发现它,则打印出来,只需用示例响应,在if结束if语句后,使用大括号
{}

if(str==5){
    break;
}
因此:


另一种方法是加载整行,在
上拆分,然后遍历以下数组,如果有5,则打印出来,如果找到,则打印出来

我认为解决方案是循环,只要没有找到数字

boolean foundFive = false;
Scanner sc = new Scanner (new File("c:/Users/ASUS/Desktop/Numbers.txt"));
while (sc.hasNextInt() && !foundFive) {
    int number = sc.nextInt();
    System.out.print(number+ " ");
    if (number == 5) {
        foundFive = true;
    }
}       
sc.close();

我认为解决方案是循环,只要没有找到数字

boolean foundFive = false;
Scanner sc = new Scanner (new File("c:/Users/ASUS/Desktop/Numbers.txt"));
while (sc.hasNextInt() && !foundFive) {
    int number = sc.nextInt();
    System.out.print(number+ " ");
    if (number == 5) {
        foundFive = true;
    }
}       
sc.close();

我认为解决方案是循环,只要没有找到数字

boolean foundFive = false;
Scanner sc = new Scanner (new File("c:/Users/ASUS/Desktop/Numbers.txt"));
while (sc.hasNextInt() && !foundFive) {
    int number = sc.nextInt();
    System.out.print(number+ " ");
    if (number == 5) {
        foundFive = true;
    }
}       
sc.close();

我认为解决方案是循环,只要没有找到数字

boolean foundFive = false;
Scanner sc = new Scanner (new File("c:/Users/ASUS/Desktop/Numbers.txt"));
while (sc.hasNextInt() && !foundFive) {
    int number = sc.nextInt();
    System.out.print(number+ " ");
    if (number == 5) {
        foundFive = true;
    }
}       
sc.close();




这个for循环是为了什么?你想做什么?你建议怎么做?你不需要这个for循环。只要使用if(str==5)你的循环实际上没有做任何事情…这个for循环是为了什么?你想做什么?你建议怎么做?你不需要这个for循环。只要使用if(str==5)你的循环实际上没有做任何事情…为了这个for循环做什么?你想做什么?你建议怎么做?你不需要这个for循环。只要使用if(str==5)你的循环实际上没有做任何事情…为了这个for循环做什么?你想做什么?你建议怎么做?你不需要这个for循环。只要使用if(str==5)你的循环实际上没有做任何事情…我建议使用大括号来避免这样的问题。你能给我举个例子吗,因为我还是初学者。你需要打破while循环。正如前面提到的,for循环是无用的。我建议使用大括号来避免这样的问题。你能给我举个例子吗,因为我还是初学者。你需要脱离while循环。正如前面提到的,for循环是无用的。我建议使用大括号来避免这样的问题。你能给我举个例子吗?因为我还是初学者,你需要脱离while循环。正如前面提到的,for循环是无用的。我建议使用大括号来避免这样的问题。你能给我举个例子吗我还是初学者,你需要打破while循环。正如前面提到的,for循环是无用的。我想显示1,2,3,4,5,而不是1,2,3,4,5,6,7,8,9,10@rickyhitman10然后看看我的代码,它会给你1 2 3 4 5或使用此代码,但将
str!=5
更改为
str!=6
。抱歉@rickyhitman 10。谢谢你指出我的错误ror.我更新了我的答案以满足您的需要此代码为您提供了休息时间。除非您计划在str==5的位置执行额外的逻辑?我想显示1,2,3,4,5,而不是1,2,3,4,5,6,7,8,9,10@rickyhitman10然后看看我的代码,它会给你1 2 3 4 5或使用此代码,但将
str!=5
更改为
str!=6
。抱歉@rickYhitman 10.谢谢你指出我的错误。我更新了我的答案以满足你的需要。该代码为你解决了问题。除非你计划在str==5的位置执行额外的逻辑?我想显示1,2,3,4,5,而不是1,2,3,4,5,6,7,8,9,10@rickyhitman10然后看我的代码,它会给你1 2 3 4 5或使用此代码,但更改
str!=5de>to
str!=6
。抱歉@rickyhitman10。感谢您指出我的错误。我更新了我的答案以满足您的需要。此代码为您提供了休息时间。除非您计划在str==5的位置执行额外逻辑?我想显示1,2,3,4,5,而不是1,2,3,4,5,6,7,8,9,10@rickyhitman10然后看看我的代码,它会给你1 2 3 4 5或使用此代码已更改,但将
str!=5
更改为
str!=6
。抱歉@rickyhitman10。感谢您指出我的错误。我更新了我的答案以满足您的需要此代码为您提供了休息时间。除非您计划在str==5的位置执行额外的逻辑?我想您可以执行foundFive=(number==5;).但那只是我的强迫症谈话。我想你可以做foundFive=(数字==5;)。但那只是我的强迫症谈话。我想你可以做foundFive=(数字==5;)。但那只是我的强迫症谈话。我想你可以做foundFive=(数字==5;)==