import java.util.Scanner;
class CharExchange
{
public static void main(String[] args)
{
System.out.print("请输入一个小写字母:");
Scanner sc=new Scanner(System.in);
char ch=sc.nextLine();
char temp =char(ch-32);
System.out.print("与其相对应的大写字母为:"+temp);
}
}
------解决方案--------------------------------------------------------
这里的ch是个字符!
------解决方案--------------------------------------------------------
sc.nextLine(); 为String 类型
强转为 (char)(ch-32);
------解决方案--------------------------------------------------------
System.out.print("请输入一个小写字母:");
Scanner sc=new Scanner(System.in);
char ch=sc.nextLine().charAt(0);
char temp = Character.toUpperCase(ch);
System.out.print("与其相对应的大写字母为:"+temp);
------解决方案--------------------------------------------------------
------解决方案--------------------------------------------------------
public static void main(String[] args)
{
System.out.print("请输入一个小写字母:");
Scanner sc=new Scanner(System.in);
String ch=sc.nextLine();
char[] temp =ch.toCharArray();
for(char tem : temp){
tem = (char) (tem - 32);
System.out.print("与其相对应的大写字母为:"+tem);
}
}
}