2013-05-28 33 views
-1
I have an input of 
-157,118 
-170,12 
-74,139 
-144,42 
-155,196 
122,-88 
-187,-143 
156,-18 
-67,126 
44,-102 
.... 

這樣.I必須檢查在一個文件中的每個數(其中i有更多的輸入,比如這些)和必須找到哪一對屬於(+ VE,霧化+ ve ).plese任何人幫助我。我是能夠從文件中讀取。我已經做了這個數字..如何使在Java正數的座標

public class EulerGift { 

public static void main(String[] args) { 

    // List<String> coordinateList=new ArrayList<String>(); 
    File file = new File("D:/coordinate.txt"); 

    try { 

     Scanner sc = new Scanner(file); 

     while (sc.hasNext()) { 

      String value = sc.next(); 

      String[] tokens = value.split(","); 

      for (int i = 0; i < tokens.length; i++) { 

        System.out.println("("+Integer.parseInt(tokens[i])+")"); 
        // System.out.println(Integer.parseInt(tokens[i])); 
      } 
     } 
    } catch (FileNotFoundException e) { 
     System.err.format("File Not Found"); 
    } 
} 
} 
+0

我們展示的代碼你在哪裏閱讀文件中的數字...你只能在那裏檢查它是否是數字。 –

+0

我在編輯我的帖子 – Mandrek

+2

你需要澄清你的問題。什麼是+ ve?我假設這是作業。你問如何打開一個文件?或者如何比較兩個值?從詢問問題的方式來看,它可能也是。 – spuder

回答

1

如果你只是想獲得正對:

String value = sc.next(); 
String[] tokens = value.split(","); 
int[] values = new int[2]; 

values[0] = Integer.parseInt(tokens[0]) 
values[1] = Integer.parseInt(tokens[1]) 
if(values[0]>0 && values[1]>0) 
    System.out.println("(" + values[0] + "," + values[1] + ")"); 
+2

誰downvoted這個需要解釋他們的推理。我沒有看到這個答案有什麼問題。 –

+0

謝謝它的工作正常 – Mandrek