qq_零_14
2015-11-29 22:03
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("淘汰");
}
}
}
这个我运行不出来,提示
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
Syntax error on tokens, delete these tokens
Type mismatch: cannot convert from boolean to String
Syntax error, insert ";" to complete LocalVariableDeclarationStatement
sex cannot be resolved to a variable
Syntax error on token "else", delete this token
at com.imooc.HelloWorld.main(HelloWorld.java:4)
你写的是java?
public class HelloWorld {
public static void main(String[] args) {
int score = 94;
String seX="女";
if(score>80){
if(seX=="男"){//相等最好用seX.equals("男")
System.out.println("进入男子组决赛");
}else{
System.out.println("进入女子组决赛");
}
}else{
System.out.println("淘汰");
}
}
}
现在回头来看,当时真的太年轻,谢谢各位好心人啊 。
public class HelloWorld {
public static void main(String[] args) {
int score = 94;
String sex = "女";
if(score>80){
if(sex.equals("女")){
System.out.println("进入女子组决赛");
}else{
System.out.println("进入男子组决赛");
}
}
}
}
public class HelloWorld {
public static void main(String[] args) {
int score = 94;
String sex = "女";
if(score>80){
if(sex squals("女")){
System.out.println("进入女子组决赛");
}else{
System.out.println("进入男子组决赛");
}
}
}
}
X我已经改了
Java入门第一季(IDEA工具)升级版
1165550 学习 · 17586 问题
相似问题