
编写java程序,将从标准输入读取的每行字符串在屏幕上回应显示出来。
3个回答
展开全部
import java.io.*;//由于需要用到流,所以把这个包import进来
public class StdIo
{
public static void main(String args[])
{
String str=null;//定义个接受输入标准输入
BufferedReader stdIn=new BufferedReader(new InputStreamReader(System.in));
try//用到流时需要抛出异常
{
str=stdIn.readLine();//读入一行
//如果想要得到个数字,可以通过下面的转换
//int a=Integer.parseInt(str);
//如果向转换为浮点型可用Float.parseFloat();……
System.out.println(str);//输出该行
}
catch(IOException e)
{
System.out.println("IO Error!");
}
}
}
public class StdIo
{
public static void main(String args[])
{
String str=null;//定义个接受输入标准输入
BufferedReader stdIn=new BufferedReader(new InputStreamReader(System.in));
try//用到流时需要抛出异常
{
str=stdIn.readLine();//读入一行
//如果想要得到个数字,可以通过下面的转换
//int a=Integer.parseInt(str);
//如果向转换为浮点型可用Float.parseFloat();……
System.out.println(str);//输出该行
}
catch(IOException e)
{
System.out.println("IO Error!");
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JTextArea;
public class Test47 extends JFrame {
JTextArea jta = new JTextArea(10, 20);
public Test47() {
add(jta);
pack();
setLocation(300, 200);
setVisible(true);
}
public void go() {
String s = JOptionPane.showInputDialog(null, "请输入:");
jta.append(s);
jta.append("\n");
}
public static void main(String[] args) {
Test47 t47=new Test47();
while(true){
t47.go();
}
}
}
import javax.swing.JOptionPane;
import javax.swing.JTextArea;
public class Test47 extends JFrame {
JTextArea jta = new JTextArea(10, 20);
public Test47() {
add(jta);
pack();
setLocation(300, 200);
setVisible(true);
}
public void go() {
String s = JOptionPane.showInputDialog(null, "请输入:");
jta.append(s);
jta.append("\n");
}
public static void main(String[] args) {
Test47 t47=new Test47();
while(true){
t47.go();
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Scanner scanner = new Scanner(System.in);
while(true){
String msg = scanner.next();
System.out.println(msg);
}
while(true){
String msg = scanner.next();
System.out.println(msg);
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询