Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package examen2;
- import java.io.*;
- import java.util.*;
- public class Examen2 {
- public static void main(String[] args) throws Exception {
- FileInputStream fis = new FileInputStream("dataIn.txt");
- BufferedReader br = new BufferedReader(new InputStreamReader(fis));
- TreeSet<Punct> set = new TreeSet();
- String line;
- //problem in the while statement
- while (((line = br.readLine()).length() != 0)) {
- String[] splited = line.split("([^0-9\n\r\-][^0-9\n\r\-]*)");
- int[] number = new int[splited.length];
- for (int i=0, j=0; i<splited.length; i++) {
- number[j] = Integer.parseInt(splited[i]);
- j++;
- }
- set.add(new Punct(number[0], number[1]));
- Iterator it = set.iterator();
- while (it.hasNext()) {
- System.out.print(it.next());
- }
- System.out.println();
- }
- br.close();
- br = null;
- fis = null;
- }
- static class Punct implements Comparable {
- int x;
- int y;
- Punct() {
- x = 0;
- y = 0;
- }
- Punct(int x, int y) {
- this.x = x;
- this.y = y;
- }
- @Override
- public String toString() {
- return "(" + this.x + ":" + this.y + ")";
- }
- @Override
- public boolean equals(Object o) {
- try {
- Punct other = (Punct)o;
- return (this.x==other.x && this.y==other.y);
- } catch (Exception ex) {
- System.out.println(ex.getMessage());
- }
- return false;
- }
- @Override
- public int compareTo(Object t) {
- Punct other = (Punct)t;
- if (this.x == other.x && this.y == other.y) {
- return 0;
- } else if (Math.sqrt(Math.pow(this.x, 2)+Math.pow(this.y, 2))-Math.sqrt(Math.pow(other.x, 2)+Math.pow(other.y, 2))>0) {
- return 1;
- } else {
- return -1;
- }
- }
- @Override
- public int hashCode() {
- return super.hashCode(); //To change body of generated methods, choose Tools | Templates.
- }
- @Override
- protected void finalize() throws Throwable {
- super.finalize(); //To change body of generated methods, choose Tools | Templates.
- }
- @Override
- protected Object clone() throws CloneNotSupportedException {
- return super.clone(); //To change body of generated methods, choose Tools | Templates.
- }
- }
- }
- at examen2.Examen2.main(Examen2.java:15)
- while (((line = br.readLine()).length() != 0)) {
- while((line=br.readLine())!=null) {
- //....
- }
- while (((line = br.readLine()).length() != 0)) {
- while ((line = br.readLine() != null) {
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement