public class Test{ int x=-10 ,y=0 ;
y=x>=0?x:-x;
public static void main(String[]args)
{
System.out.println("the abs of "+x+" is "+y);
}
}
总提示:Test.java:4 错误: 需要<标识符>
y=x>=0?x:-x;
^改为下面的代码则不会出错。为什么?
public class Test{ public static void main(String[]args)
{
int x=-10 ,y=0 ;
y=x>=0?x:-x;
System.out.println("the abs of "+x+" is "+y);
}
}
谢谢! ^
y=x>=0?x:-x;
public static void main(String[]args)
{
System.out.println("the abs of "+x+" is "+y);
}
}
总提示:Test.java:4 错误: 需要<标识符>
y=x>=0?x:-x;
^改为下面的代码则不会出错。为什么?
public class Test{ public static void main(String[]args)
{
int x=-10 ,y=0 ;
y=x>=0?x:-x;
System.out.println("the abs of "+x+" is "+y);
}
}
谢谢! ^
http://topic.csdn.net/u/20091221/19/ef37eceb-6f8e-40ee-8695-7b132c2f292f.html
上面的语句不是变量定义语句,不是方法定义,不在代码块{}里,所以报错!