当前位置: 技术问答>java相关
How can I convert a Char type to a Integer type?
来源: 互联网 发布时间:2015-05-09
本文导语: I want this function: receive a char: '3' by System.in.read(); and convert it to integer 3; but I always get 51 now. I know 51 is the ASCII for 3; How can I convert char '3' to integer 3? waiting online... | ...
I want this function:
receive a char: '3' by System.in.read();
and convert it to integer 3;
but I always get 51 now.
I know 51 is the ASCII for 3;
How can I convert char '3' to integer 3?
waiting online...
receive a char: '3' by System.in.read();
and convert it to integer 3;
but I always get 51 now.
I know 51 is the ASCII for 3;
How can I convert char '3' to integer 3?
waiting online...
|
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);
}
}
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);
}
}