JAVA里让用户从键盘输入一个字符串得语句怎么写?

2024-11-17 17:51:52
推荐回答(2个)
回答1:

import java.io.*;
public class SimpleIO
{
public static void main(String [ ]args)
{
String s="";
System.out.println("请输入一个字符串:");
try{
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
s=in.readLine();
}catch(IOException e){System.out.println("产生异常");}
System.out.println("你输入的字符串是"+s);
}
}

回答2:

public static void main(String args[]){
int count;
byte buf[]=new byte[255];
System.out.print("提示输入:");
try{
count=System.in.read(buf);
String str=new String(buf,0,count-2);
System.out.print("输出"+str);
}
catch(IOException e){
//捕获异常
}

}