But compile failed! prompt: getNumericValue(char) in java.lang.Character cannot be applied to (int)Why?
System.in.read()读出来的是char,当然会是ascii值了。 BufferedReader br = new BufferedReder(new OutputStreamReader(System.in))); String theNum = br.readLine(); int num = Integer.parseInt(theNum);
johnwesley(我心荡漾(终于发现无界限)) : can i view your code about this?
to: tomxutomxu(shprog).compile prompt: cannot resolve symbol symbol: class OutputStreamReader location: class Test BufferedReader br = new BufferedReader(new OutputStreamReader(System.in)); ^
To: xmvigour(微电)import java.util.*; import java.io.*;public class Test{ public static void main(String[] args){ int i = 0; try{ i = System.in.read(); System.out.println("Your input is:"+i); } catch(IOException e){} System.out.println("Length will be:"+i); } }
import java.util.*; import java.io.*;public class Test5{ public static void main(String[] args){ int i = 0; char c; int ii=0; try{ i = System.in.read(); c=(char) i; ii = Character.getNumericValue(c); //ii =Integer.parseInt(String.valueOf(c));
System.out.println("Your input is:"+c+" ascii is "+i); } catch(IOException e){} System.out.println("Length will be:"+ii); } }
johnwesley: i = System.in.read();得到的是ascii码,所以你必须转换成char,再转存为int。
orint ii =Integer.parseInt(String.valueOf(ss));
prompt:
getNumericValue(char) in java.lang.Character cannot be applied to (int)Why?
BufferedReader br = new BufferedReder(new OutputStreamReader(System.in)));
String theNum = br.readLine();
int num = Integer.parseInt(theNum);
can i view your code about this?
symbol: class OutputStreamReader
location: class Test
BufferedReader br = new BufferedReader(new OutputStreamReader(System.in)); ^
import java.io.*;public class Test{
public static void main(String[] args){
int i = 0;
try{
i = System.in.read();
System.out.println("Your input is:"+i);
}
catch(IOException e){} System.out.println("Length will be:"+i);
}
}
import java.io.*;public class Test5{
public static void main(String[] args){
int i = 0;
char c;
int ii=0;
try{
i = System.in.read();
c=(char) i;
ii = Character.getNumericValue(c);
//ii =Integer.parseInt(String.valueOf(c));
System.out.println("Your input is:"+c+" ascii is "+i);
}
catch(IOException e){} System.out.println("Length will be:"+ii);
}
}
i = System.in.read();得到的是ascii码,所以你必须转换成char,再转存为int。