2014-04-13 38 views
0

我正在編寫一個簡單的問題,其中我只需要在輸入文件的一行中總結兩個數字,並在輸出文件中輸出兩個數字的總和的結果。在線Judge的運行時錯誤

樣品輸入以下內容: -

5       //The first line is the number of test cases 
22 12 
23 12 
1 1 
2 3 
100 100 

示例輸出如下

34 
35 
2 
5 
200 

這裏是我正在做它: -

import java.util.Scanner; 
import java.io.File; 
import java.io.PrintWriter; 

public class Test131009 { 
    public static void main(String[] args)throws Exception{ 

     Scanner in = new Scanner(new File("input.txt")); 
     PrintWriter out = new PrintWriter(new File("main.out")); 

    int T = in.nextInt(); 

    for(int t = 1; t <= T; t++) { 
     int first = in.nextInt(); 
     int second = in.nextInt(); 
     int result = first + second; 
     out.println(result); 
    } 
    out.close(); 
    } 
} 

我不能找出爲什麼法官裁決出現運行時錯誤。

+1

什麼是錯誤的堆棧跟蹤? –

+0

我可以從網上裁判那裏獲得堆棧跟蹤嗎?我不知道該怎麼做。 –

+1

運行代碼以獲取堆棧跟蹤。 –

回答

0

此代碼適用於我。我只需要改變輸入形式的文件到System.in和寫入輸出也System.out

這是代碼。

import java.util.Scanner; 


public class Main { 
    public static void main(String[] args)throws Exception{ 

    Scanner in = new Scanner(System.in); 

    int T = in.nextInt(); 

    for(int t = 1; t <= T; t++) { 
     int first = in.nextInt(); 
     int second = in.nextInt(); 
     int result = first + second; 
     System.out.println(result); 
    } 

} 

}