0
Follow
0
View

Java if process statement print problem!

cynh77 注册会员
2023-02-28 06:20
cupidcool 注册会员
2023-02-28 06:20

Are you sure this else will work?

img

xye20070408 注册会员
2023-02-28 06:20

Did you save the code?

dengyijie12306 注册会员
2023-02-28 06:20

method is OK; Is sure to normal operation, in addition to the else remove < br / >

< div class = "aw - list - img > img

czytjkp 注册会员
2023-02-28 06:20

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.

cryice520 注册会员
2023-02-28 06:20

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.

About the Author

Question Info

Publish Time
2023-02-28 06:20
Update Time
2023-02-28 06:20

Related Question

按键精灵ifcolor 颜色判断(按键精灵)

如何获得托管区域名称服务器使用AWS JAVA SDK

我如何检查一个if语句的真/假值在bash?

如何运行一个java脚本(或一些)与ajax从一个单独的文件?

Java代码无法编译运行

使用hashmap JAVA确定两个排序链表之间的公共项

用javascript更新foreach循环中的数组对象

Java对象创建存储空间

如果Service Worker中有冗余的“if (false){}”,PWA不会仅在iPadOS上离线工作

使用mutate、if_else和str_detect创建一个新变量