怎样从键盘读取字符 怎样从键盘读取字符? 付给一个char变量: 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 Scanner scan = new Scanner(System.in); Scanner sca=new Scanner(System.in)char c=sca.next().charAt(0); import java.io.BufferedInputStream;import java.io.IOException;class Test { public static void main(String[] args) { BufferedInputStream is=new BufferedInputStream(System.in); char c=0; try { c=(char) is.read(); } catch (IOException e) { e.printStackTrace(); }finally{ try { is.close(); } catch (IOException e) { e.printStackTrace(); } } System.out.println(c); }} 从键盘向控制台输入数据就三种方式Scanner类Console类还有四楼的那个方式Scanner中的next()返回的是字符串,只要charAt(0)就是转换成字符了 code=Java]BufferedInputStream in=new BufferedInputStream(System.in);Scanner scan = new Scanner(System.in);[[/code] import java.util.*;(1)BufferedInputStrea bis = new BufferedInputStream(System.in)(2)Scanner scan = new Scanner(System.in); DataInputStream dis = new DataInputStream(System.in);dis.readChar();还有好多方法,看看帮助文档,io包中的类,很好理解的.. @interface 这是什么意思啊 j2se的几个问题,高手进 JTree 删除节点 无法刷新 日期计算 请问中文乱码的解决方法 jar路径问题。 用线程实现16*16矩阵相乘 这段代码是什么意思啊 疑惑JComboBox,JRadioButton的API 判断一个对象是不是NULL应该怎么判断呢?谢谢 求两个算法 字符串转化为xml文件
char c=sca.next().charAt(0);
import java.io.IOException;
class Test {
public static void main(String[] args) {
BufferedInputStream is=new BufferedInputStream(System.in);
char c=0;
try {
c=(char) is.read();
} catch (IOException e) {
e.printStackTrace();
}finally{
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
System.out.println(c);
}
}
Scanner类Console类还有四楼的那个方式
Scanner中的next()返回的是字符串,只要charAt(0)就是转换成字符了
BufferedInputStream in=new BufferedInputStream(System.in);
Scanner scan = new Scanner(System.in);[
[/code]
(1)BufferedInputStrea bis = new BufferedInputStream(System.in)
(2)Scanner scan = new Scanner(System.in);
dis.readChar();还有好多方法,看看帮助文档,io包中的类,很好理解的..