條件語句-多重if
?public?class?byThree{ ???public?static?void?main(String[]?args){ ?????int?age=(-1); ?????if?(age>=0){ ???????}if(age>=200){ ???????System.out.println("外星人"); ???????}else?if?(age>=120){ ???????System.out.println("百歲老人"); ???????}else?if?(age>=100){ ???????System.out.println("老年人"); ???????}else?if?(age>=60){ ???????System.out.println("中老年人"); ???????}else?if?(age>=40){ ???????System.out.println("中年人"); ???????}else?if?(age>=18){ ???????System.out.println("成年人"); ???????}else?if(age>=12){ ???????System.out.println("青少年"); ???????}else{ ???????System.out.println("少年"); ?????}else{ ?????System.out.println("輸入錯誤"); ?????} ??} }
哪里錯了嗎,大神指教。
2016-03-19
因為你的19行和20行都是else ? 只能有一個else
2016-02-27
public class bythree{
? public static void main(String[] args){
? ? int age=(-1);
? ? if (age>=0){
? ? ? if(age>=200){
? ? ? System.out.println("外星人");
? ? ? }else if (age>=120){
? ? ? System.out.println("百歲老人");
? ? ? }else if (age>=100){
? ? ? System.out.println("老年人");
? ? ? }else if (age>=60){
? ? ? System.out.println("中老年人");
? ? ? }else if (age>=40){
? ? ? System.out.println("中年人");
? ? ? }else if (age>=18){
? ? ? System.out.println("成年人");
? ? ? }else if(age>=12){
? ? ? System.out.println("青少年");
? ? ? }else{
? ? ? System.out.println("少年");
? ? }
? ? } else{
? ? System.out.println("輸入錯誤");
? ? }
?}
}
大括號錯了
2016-02-27
1、第五行第一個“{”要刪掉