问题: 利用while语句和System.in.read()语句统计从键盘上输入字符的个数?
关键词:
import java.io.*;
throws IOException
System.out.print(b);
b = (char) System.in.read();
package henu.edu.cn;
import java.util.*;
import java.io.*; //import java.io.*;
public class LSH {
public static void main(String args[]) throws IOException //throws IOException
{
Scanner reader = new Scanner(System.in);
System.out.print("输入:");
char b;
int count=0;
b = (char) System.in.read(); //***
while (b != '\r') // '\r'是回车。
{
System.out.print(b);
count++;
b = (char) System.in.read(); //****
}
System.out.print("\n您输入了" + count + "个字符");
System.out.println(b);
reader.close();
}
}