如果你在做hdu 1073,hdu 1075就会发现这个问题。
嘿嘿!这是给新手看的,,,毕竟这题让我太纠结了,wa了不知道多少次了,心都塞了。
后来我发现是我的输入方式不对,大家可以对比输入的数据,当然前面两题我都发在博客里了,可以在搜索栏搜索到。
错误的输入:
错误1)
import java.util.Scanner;
public class p1075 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// 输入字典的部分
String s = new String();
s = sc.nextLine();// 这里可能有制表符
s = sc.nextLine();// 覆盖start一行数据
while (!s.equals("END")) {
s += "\n";// 用换行符就可以单行显示,避免数据不显示
s += sc.nextLine();
}
System.out.println("++s++" + s);
}
}
错误2)
import java.util.Scanner;
public class p1075 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// 输入字典的部分
String s = new String();
s = sc.nextLine();// 这里可能有制表符
s = sc.nextLine();// 覆盖start一行数据
while (!s.equals("END")) {
s += "\n";// 用换行符就可以单行显示,避免数据不显示
s += sc.nextLine();
System.out.println("1" + s);
}
System.out.println("++s++" + s);
}
}
输出结果正确
错误3)
import java.util.Scanner;
public class p1075 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// 输入字典的部分
String s = new String();
s = sc.nextLine();// 这里可能有制表符
s = sc.nextLine();// 覆盖start一行数据
while (!s.equals("END")) {
s += "\n";// 用换行符就可以单行显示,避免数据不显示
s += sc.nextLine();
System.out.println("1" + s);
}
System.out.println("++s++" + s);
// 再输入
String s2 = new String();
s = sc.nextLine();
s = sc.nextLine();
while (!s2.equals("END")) {
s2 += "\n";// 用换行符就可以单行显示,避免数据不显示
s2 += sc.nextLine();
}
System.out.println("++s2++" + s2);
}
}
第二个入错误
正确的输入:
import java.util.Scanner;
public class P1075a {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String s1 = "";// 接输入的字符
String a = "";
s1 = sc.nextLine();
s1 = sc.nextLine();
int count = 0;
while (!s1.equals("END")) {
if (count != 0) {
a += "\n";
}
count++;
a += s1;
s1 = sc.nextLine();
}
System.out.println("a: " + a);
}
}