Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package PROBLEM_1;
- import java.util.Scanner;
- import java.util.*;
- public class Program_1 {
- public static void main(String[] args) {
- int xcordin[] = {1,3,5,9,11,11,9,17,22,25,21,28,30,31,8,26,35};
- int ycordin[] = {5,30,10,24,22,20,4,25,30,19,5,32,31,1,35,2,15};
- int nearest[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,};
- int stationx[] = {8,35}; // index 0 is station 1's x, index 1 is station 2's x
- int stationy[] = {16,13}; //index 0 is station 1's y, index 1 is station 2's y
- int x2;
- int y2;
- double s1dis; //distance to station 1
- double s2dis; //distance to station 2
- int sx1 = stationx[0];
- int sy1 = stationy[0];
- int sx2 = stationx[1];
- int sy2 = stationy[1];
- System.out.println("0 = both");
- for(int i = 0; i < xcord.length; i++){
- x2 = xcordin[i];
- y2 = ycordin[i];
- s1dis = Math.sqrt(Math.pow((x2 - sx1),2)/Math.pow((y2 - sy1),2));
- s2dis = Math.sqrt(Math.pow((x2 - sx2),2)/Math.pow((y2 - sy2),2));
- for (int f =0; f < nearest.length; f++){
- if(s1dis > s2dis){
- nearest[f] = 2;
- }
- else if(s2dis > s1dis){
- nearest[f] = 1;
- }
- else if(s2dis == s1dis){
- nearest[f] = 0;
- }
- }
- System.out.println((i+1) +" ("+ xcordin[i] + "," + ycordin[i] + ") Nearest station: " + nearest[i]);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement