Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package hello;
- import java.io.BufferedReader;
- import java.io.FileReader;
- import java.util.ArrayList;
- import java.util.Scanner;
- public class sasiedzi
- {
- public static class Point
- {
- // public int x;
- // public int y;
- // public int z;
- // public int a;
- ArrayList<int> punkty;
- }
- public static void main(String [ ] args)
- {
- Scanner co = new Scanner(System.in);
- //String filename = co.nextLine();
- String filename="D:/sa.txt";
- try
- {
- BufferedReader reader = new BufferedReader(new FileReader(filename));
- ArrayList<Point> pts = new ArrayList<Point>();
- String line;
- while((line = reader.readLine()) != null)
- {
- String [] data = line.split(" ");
- Point pt = new Point();
- for(int i =0; i < data.length; i++)
- System.out.println(data[i]);
- // pt.x = Integer.valueOf(data[0]);
- // pt.y = Integer.valueOf(data[1]);
- // pt.z = Integer.valueOf(data[2]);
- pts.add(pt);
- }
- reader.close();
- System.out.println("Podaj x");
- String xStr = co.nextLine();
- System.out.println("Podaj y");
- String yStr = co.nextLine();
- System.out.println("Podaj z");
- String zStr = co.nextLine();
- Point pt = new Point();
- pt.x = Integer.valueOf(xStr);
- pt.y = Integer.valueOf(yStr);
- pt.z = Integer.valueOf(zStr);
- double distance = Float.MAX_VALUE;
- Point neighboor = null;
- for(Point p : pts)
- {
- double dx = p.x - pt.x;
- double dy = p.y - pt.y;
- double dz = p.z - pt.z;
- double d = Math.sqrt(dx*dx+dy*dy+dz*dz);
- if(d < distance)
- {
- distance = d;
- neighboor = p;
- }
- }
- System.out.printf("Najbliższy sąsiad to %d,%d,%d w odległości %f",neighboor.x,neighboor.y,neighboor.z,distance);
- co.nextLine();
- co.close();
- }
- catch(Exception exc)
- {
- System.out.println("nie można otworzyć pliku");
- return;
- }
- }
- private static String valueOf(String string) {
- // TODO Auto-generated method stub
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement