seiko
2016-05-19 21:09
public class HelloWorld {
public static void main(String[] args) {
int one = 21 ;
if (one%2==0){
res = "偶数";
else
res = "奇数";
System.out.println("one是"+res);
}
}
}
public class HelloWorld
{
public static void main(String[] args)
{
int one = 21 ;
String res = "";
if (one%2==0)
{
res = "偶数";
}
else
res = "奇数";
System.out.println("one是"+res);
}
}
第一个问题是你的res没有定义类型,第二个问题是else不能放在if后面的括号里
public class HelloWorld {
public static void main(String[] args) {
int one = 21 ;
if (one%2==0){
String res = "偶数";
}else{
String res = "奇数";
System.out.println("one是"+res);
}
}
}
public class HelloWorld {
public static void main(String[] args) {
int one = 21 ;
if (one%2==0){
System.out.println("one是偶数“);
}
else{
System.out.println("one是奇数“);
}
}
}
Java入门第一季(IDEA工具)升级版
1165559 学习 · 17587 问题
相似问题