- helps you find a similar problem, you can look at: https://ask.csdn.net/questions/7660656
0 Answer
method is OK; Is sure to normal operation, in addition to the else remove < br / >
< div class = "aw - list - img >
The answer part references GPT, GPT_Pro better solve the problem
Maybe you have a problem with your if statement, Java if flow statement format is:
if(条件){
//执行的代码
}else if(条件){
//执行的代码
}else{
//执行的代码
}
For example, if you ask for 33, print it out in the second interval, then write:
int num = 33;
if (num >= 0 && num <= 20) {
System.out.println("在第一区间");
} else if (num > 20 && num <= 50) {
System.out.println("在第二区间");
} else {
System.out.println("在第三区间");
}
If the answer is helpful, please accept it.
the reference answer GPT ᴼ ᴾ ᴱ ᴺ ᴬ ᴵ < br / > in the code, the judgment of the second if statement conditions there is a mistake. It should be m< =70, not 6m< Is equal to 70. This error causes 33 not to enter the second if statement, so the information in the second interval cannot be printed.
You can put & & & This is a common logical error. Also, pay attention to code formatting, such as capitalization, parentheses, semicolons, and so on, to avoid compilation errors. The modified code is as follows:
import java.util.Scanner;
public class Test4 {
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("输入数宇m");
int m = sc.nextInt();
if (m >= 10 && m <= 30) {
System.out.println("m在第一区间");
} else if (m >= 30 && m <= 70) {
System.out.println("m在第二区间");
} else if (m >= 70 && m <= 100) {
System.out.println("m在第三区间");
} else {
System.out.println("m不在任何区间");
}
}
}
This correctly prints the information that m is in the second interval when the input is 33.
这家伙很懒,什么都没留下...