不知道哪里錯了
public class HelloWorld {
? ? public static void main(String[] args) {
int score = 94;
String sex = "女";
? ? ? ? if(score>80){
? ? ? ? if(sex=="男"){
? ? ? ? System.out.println("進入男子組決賽");
? ? ? ? }else{
? ? ? ? ? ? System.out.println("進入女子組決賽");
? ? ? ? }else{
? ? ? ? System.out.println("淘汰");
? ? ? ? }
? ? ? ??
? ? ? ??
? ? ? ?
}
}
2015-09-21
? System.out.println("進入女子組決賽");的后面
這里掉了個"}"
2015-09-21
括號是成對出現的,發現了沒有,代碼里第二個if缺個結束的}。注意代碼的縮進格式化,這樣更易于閱讀。
修改后的代碼
public?class?HelloWorld?{ ????public?static?void?main(String[]?args)?{ ????????int?score?=?94; ????????String?sex?=?"女"; ????????if(score>80){ ????????????if(sex=="男"){ ????????????System.out.println("進入男子組決賽"); ????????????}else{ ????????????System.out.println("進入女子組決賽"); ????????????} ????????}else{ ????????System.out.println("淘汰"); ????????} ???????? ????} }2015-09-21
public class HelloWorld {
仔細看看,少了一個括號啊。
? ? public static void main(String[] args) {
int score = 94;
String sex = "女";
? ? ? ? if(score>80){
? ? ? ? if(sex=="男"){
? ? ? ? System.out.println("進入男子組決賽");
? ? ? ? }else{
? ? ? ? ? ? System.out.println("進入女子組決賽");
? ? ? ? }
????????}????????????? ?//--------------------這里少了一個大括號
????????else{
? ? ? ? System.out.println("淘汰");
? ? ? ? }
? ? ? ??
? ? ? ??
? ? ? ?
}
}