import java.io.*;
public class zimu{
public static void main(String [] args){
int ch= 'e ';
ch=(ch> = 'a '&&ch <= 'z ')?(ch-32):ch;
System.out.println( "ch= "+ch);
}
}
这输出的是个ascii码的值 怎么才能让他输出大写?
------解决方案--------------------
你现在的ch不就是大写的ascii码的值吗?
------解决方案--------------------
System.out.println( "ch= "+(char)ch);
将ch显式转换为char型
------解决方案--------------------
public class zimu {
public static void main(String [] args){
char ch= 'e ';
ch=(char) ((ch> = 'a '&&ch <= 'z ')?(ch-32):ch);
System.out.println( "ch= "+ch);
}
}
------解决方案--------------------
2楼的程序输入ch=E
------解决方案--------------------
int ch= 'e ';
改为:char ch= 'e ';
------解决方案--------------------
public class ch {
public static void main(String args[])
{
char ch= 'E ';
if(ch> = 'A '&&ch <= 'Z ')
{
int b=ch+32;
System.out.println((char)b);
}
else
System.out.println( "ch不是小写字母 ");
}
}