本帖最后由 曾德强 于 2013-5-13 21:11 编辑
- package com.IO;
- import java.io.*;
- public class SystemIO {
- /**
- * @param args
- */
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- try{
- InputStreamReader fis=new InputStreamReader(System.in);
- BufferedReader re=new BufferedReader(fis);
- int read=fis.read();
- while(read!=-1&read!='e'&read!='E'){
- System.out.print((char)read);
- read=fis.read();
- }
- }
- catch(IOException e){
- e.printStackTrace();
- }
- }
- }
复制代码 最简单的一种
另一种就是楼上所说的- package com.IO;
- import java.util.Scanner;
- public class Scannera {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- readString("请输入字符串:");
- System.out.println("完成输入!");
- }
- public static void readString(String prompt)
- {
- Scanner scanner = new Scanner(System.in);
- System.out.print(prompt);
- String s=scanner.nextLine();
- while(!s.equals("e")&!s.equals("E")){
- System.out.println(s);
- s=scanner.nextLine();
- }
- }
- }
复制代码 |