我試圖解決關於spoj的問題,但我的答案是不接受錯誤的答案,我想知道這兩個代碼塊之間的區別。這兩個區別
SPOJ接受本
public class Test {
public static void main(String[] args) throws java.lang.Exception {
java.io.BufferedReader r = new java.io.BufferedReader(
new java.io.InputStreamReader(System.in));
String s;
while (!(s = r.readLine()).startsWith("42"))
System.out.println(s);
}
}
但SPOJ不接受這個
class Test {
public static void main(String[] args) throws java.io.IOException {
new Test().universe();
}
public void universe() throws java.io.IOException {
System.out.println("Enter Number");
java.util.Scanner scan = new java.util.Scanner(System.in);
String input;
while (!(input = scan.next()).startsWith("42")){
System.out.println(input);
}
scan.close();
}
}
這裏的問題http://www.spoj.com/problems/TEST/
對於錯誤我很抱歉我修復了錯字 – 2014-09-20 15:27:31
第一塊代碼重新格式化以提高可讀性。 – 2014-09-20 15:32:58