Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. package PROBLEM_1;
  2. import java.util.Scanner;
  3. import java.util.*;
  4.  
  5.  
  6. public class Program_1 {
  7.  
  8. public static void main(String[] args) {
  9. int xcordin[] = {1,3,5,9,11,11,9,17,22,25,21,28,30,31,8,26,35};
  10. int ycordin[] = {5,30,10,24,22,20,4,25,30,19,5,32,31,1,35,2,15};
  11. int nearest[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,};
  12. int stationx[] = {8,35}; // index 0 is station 1's x, index 1 is station 2's x
  13. int stationy[] = {16,13}; //index 0 is station 1's y, index 1 is station 2's y
  14. int x2;
  15. int y2;
  16. double s1dis; //distance to station 1
  17. double s2dis; //distance to station 2
  18. int sx1 = stationx[0];
  19. int sy1 = stationy[0];
  20. int sx2 = stationx[1];
  21. int sy2 = stationy[1];
  22. System.out.println("0 = both");
  23. for(int i = 0; i < xcord.length; i++){
  24. x2 = xcordin[i];
  25. y2 = ycordin[i];
  26. s1dis = Math.sqrt(Math.pow((x2 - sx1),2)/Math.pow((y2 - sy1),2));
  27. s2dis = Math.sqrt(Math.pow((x2 - sx2),2)/Math.pow((y2 - sy2),2));
  28. for (int f =0; f < nearest.length; f++){
  29. if(s1dis > s2dis){
  30. nearest[f] = 2;
  31. }
  32. else if(s2dis > s1dis){
  33. nearest[f] = 1;
  34. }
  35. else if(s2dis == s1dis){
  36. nearest[f] = 0;
  37. }
  38. }
  39. System.out.println((i+1) +" ("+ xcordin[i] + "," + ycordin[i] + ") Nearest station: " + nearest[i]);
  40.  
  41. }
  42.  
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement