java输出,为什么不输出字符,而是输出字符的ASCII码啊,求大神指点迷津
import java.util.Scanner;
public class Ja9_7 {
/** * @param args */
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner(System.in);
System.out.print("Enter a string : ");
String s = input.next();
for(int i = 0;i < s.length();i++){
System.out.print(s.charAt(i) + \\/);//这里输出字符,这是我检验用的实验语句 System.out.println(Character.isLetter(s.charAt(i)) ? getNumber(Character.toUpperCase(s.charAt(i))) : s.charAt(i)(但是这里输出的是ASCII码,为什么啊,没有隐式的转换啊));
} }
public static int getNumber(char uppercaseLetter){
if(uppercaseLetter == 'A' || uppercaseLetter == 'B' ||uppercaseLetter == 'C' ) return 2;
if(uppercaseLetter == 'D' || uppercaseLetter == 'E' ||uppercaseLetter == 'F' ) return 3;
if(uppercaseLetter == 'G' || uppercaseLetter == 'H' ||uppercaseLetter == 'I' ) return 4;
if(uppercaseLetter == 'J' || uppercaseLetter == 'K' ||uppercaseLetter == 'L' ) return 5;
if(uppercaseLetter == 'M' || uppercaseLetter == 'N' ||uppercaseLetter == 'O' ) return 6;
if(uppercaseLetter == 'P' || uppercaseLetter == 'Q' ||uppercaseLetter == 'R' ||uppercaseLetter == 'S')
return 7;
if(uppercaseLetter == 'T' || uppercaseLetter == 'U' ||uppercaseLetter == 'V' ) return 8;
if(uppercaseLetter == 'W' || uppercaseLetter == 'X' ||uppercaseLetter == 'Y' ||uppercaseLetter == 'Z')
return 9;
return 0; }}
------解决方案--------------------
今天早上特意试了一下,我确实是记错了。。。
做了一个小例子,
public static void main(String args[]) {
char c1='a';
int c2=98;
boolean flag=Math.random()>0.5?true:false;
System.out.println(flag);
System.out.println(flag?c1:c2);
System.o