-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
....

像这样。我必须检查文件中的每个数字(我有更多这样的输入)并且必须找到属于 (+ve,+ve) 的对。请任何人帮助我。我能够从文件.我已经这样做了..

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");
    }
}
}
4

1 回答 1

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] + ")");
于 2013-05-28T14:47:20.203 回答