我正在尝试使用scanner.nextInt()分配两个变量L和R.赋值后,这些变量立即用于for循环。我的问题是扫描程序流在命令行保持打开状态,程序从不执行后续的for循环。这是一个片段:
System.out.println("Enter the Left and Right endpoints: ");
L = sc.nextInt();
R = sc.nextInt();
for (int i = L; i < R; i += resolution) {
double a = i, b = resolution+i;
if (poly(C, a)*poly(C, b) < 0) {
double mid = findRoot(C, a, b, tolerance);
System.out.println(mid);
if (Math.abs(poly(C, mid)) < threshold){
System.out.println("Root found at: "+mid);
numCount = 1;
}
} else if (poly(D, a)*poly(D, b) < 0) {
double mid = findRoot(D, a, b, tolerance);
if(Math.abs(poly(C, mid)) < threshold) {
System.out.println("Root found at: "+mid);
numCount = 2;
} else {
numCount = 3;
System.out.println("No roots were found in the specified range.");
}
System.out.println("numCount is "+numCount); break;
}
}