You are requested to output what you got from the system console.
Input: A line of string, until no inut is found! Example:
This is the first line.
This is the second line.
...
This is the end.
Output: What you get from the console(keyboard)
This is the first line.
This is the second line.
...
This is the end.
Hints:
On getting input from the console, you can refer to the article. For reading a line from the console, here is a example:
Scanner s = new Scanner(System.in);
if (s.hasNextLine()) {
String line = s.nextLine();
......
}
Input: A line of string, until no inut is found! Example:
This is the first line.
This is the second line.
...
This is the end.
Output: What you get from the console(keyboard)
This is the first line.
This is the second line.
...
This is the end.
Hints:
On getting input from the console, you can refer to the article. For reading a line from the console, here is a example:
Scanner s = new Scanner(System.in);
if (s.hasNextLine()) {
String line = s.nextLine();
......
}
2. 把非空的行存入一个List
3. 输出List中的行
引用 1 楼 的回复:1. 取得输入的行是不是空的,用String.isEmpty()判断,如果是空行,则退出while 循环
2. 把非空的行存入一个List
3. 输出List中的行对古云山大uifhl;空间的
sdfgdf
+ 167765087 Java开发技术交流
我们都理解错了
import java.util.Scanner;
class Main{
public static void main(String[] args) {
Scanner s =new Scanner(System.in);
while (true)
{
if(s.hasNextLine()){
String string =s.nextLine();
System.out.println(string);
}
else{
break;
}
}
}
}