为了账号安全,请及时绑定邮箱和手机立即绑定

哪里错了?

public class HelloWorld {

    public static void main(String[] args) {

int age=25;

if (age>60){

System.out.println("老年");}

else if (age>40&&age<60){

System.out.println("中年");}

else if (age>18&&age<40){

System.out.println("少年");}

else (age<18){

System.out.println("童年");}

    

    

    


正在回答

6 回答

最后一个esle不能有判断条件了。那个是是最后的。

0 回复 有任何疑惑可以回复我~

esle后边不能有中括号


0 回复 有任何疑惑可以回复我~

第一:所有大于号小于号都要空格开来不能连起来。你连起来age>18 编译器不知道你这是啥,变量?还是啥其他的?

第二:小括号和分号双引号是英语的不是中文的

第三:最后的else不需要加括号了。因为逻辑“否则”上已经满足了年龄小于18

0 回复 有任何疑惑可以回复我~

else 不能再加括号说明年龄了。

0 回复 有任何疑惑可以回复我~

public class HelloWorld {

    public static void main(String[] args) {

int age=25;

if (age>=60){

System.out.println("老年");

}

else if (age>=40&&age<60){

System.out.println("中年");

}

else if (age>=18&&age<40){

System.out.println("少年");

}

else {

System.out.println("童年");

}


0 回复 有任何疑惑可以回复我~

public class HelloWorld {


    public static void main(String[] args) {


int age=25;


if (age>60){


System.out.println("老年");}


else if (age>40){


System.out.println("中年");}


else if (age>18){


System.out.println("少年");}


else {


System.out.println("童年");}


}


}


0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

哪里错了?

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信