java基础三元运算简单运用时出现错误等待高手解答,谢谢
class example1
{
public void xy(char x)
{
char i = x;
char y=(char)(i+32);
boolean flag =i==65;
System.out.println(flag);
System.out.println(y);
flag ? i : (char)(i+32);
System.out.println(i);
}
public static void main(String[] args)
{
example1 e =new example1();
e.xy( 'A ');
}
}
错误信息:
example1.java:11: not a statement
flag ? i : (char)(i+32);
^
1 error
------解决方案--------------------flag ? i : (char)(i+32);
Type mismatch: cannot convert from char to boolean
改为:
i = flag ? i : (char) (i + 32);