public class Demo
{
public static void main(String[] args)
{
int a=10,b=20;
short c = (a<b)?a:b;
System.out.println(c);
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的程序,我得到以下错误,为什么我没有得到
"Demo.java:6: error: incompatible types: possible lossy conversion from int to short
short c = (a<b)?a:b;
1 error"
Run Code Online (Sandbox Code Playgroud)
我用变量声明写"final",它工作正常.但为什么会这样呢?
public class Demo
{
public static void main(String[] args)
{
final int a=10,b=20;
short c = (a<b)?a:b;
System.out.println(c);
}
}
Run Code Online (Sandbox Code Playgroud) java ×1