java中char的控制台输入函数是什么?
1、接收整数:
int a = 0;
try {
System.out.print("请输入a的值:"); // 提示用户输入数据
a = Integer.parseInt((new BufferedReader(new InputStreamReader(System.in))).readLine()); //将用户输入的值赋给a
} catch (Exception e) {
}
2、接收小数:
float f = 0.0f;
try {
System.out.print("请输入f的值:");
f = Float.parseFloat((new BufferedReader(new InputStreamReader(System.in))).readLine());
} catch (Exception e) {
}
double e = 0.0;
try {
System.out.print("请输入e的值:");
e = Double.parseDouble((new BufferedReader(new InputStreamReader(System.in))).readLine());
} catch (Exception e) {
}
3、接收字符的值:
char c = 0;
System.out.println("请输入运算符:");
try {
c = (char) System.in.read();
System.in.skip(2);
} catch (Exception e) {
}
4、接收字符串的值:
String str = null;
System.out.println("请输入字符串:");
try {
str = (new BufferedReader(new InputStreamReader(System.in))).readLine();
} catch (Exception e) {
}