java中char的控制台输入函数是什么
3个回答
展开全部
全部贴出 楼主要的是第三个 嗯哪 给最佳吧
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) {
}
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) {
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
没有直接读char的
只能读到string再取char
Scanner scanner = new Scanner(System.in);
char charFromConsole = scanner.next().charAt(0);
只能读到string再取char
Scanner scanner = new Scanner(System.in);
char charFromConsole = scanner.next().charAt(0);
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询