fork(1) download
  1. import java.text.DecimalFormat;
  2. import java.util.Scanner;
  3. public class PointsTest
  4. {
  5. public static void main( String[] args )
  6. {
  7. Points application = new Points();
  8. application.calculateDistance();
  9. }
  10. }
  11. public class Points {
  12.  
  13. double X, Y;
  14. double x2, y2;
  15. double Distance;
  16.  
  17.  
  18. public double calculateDistance(){
  19. Scanner keyboard = new Scanner(System.in);
  20.  
  21. System.out.print("Type the end-of-file indicator to terminate\n" +
  22. "On UNIX/Linux/Mac OS X type <Ctrl> d then press Enter\n" +
  23. "On Windows type <Ctrl> z then press Enter ");
  24.  
  25. String input = keyboard.nextLine();
  26. char EndOfFile = input.charAt(0);
  27. if (EndOfFile == 'Z'|| EndOfFile =='z' || EndOfFile =='d'|| EndOfFile =='D') //If Z,z,d,D is pressed program ends. Works fine.
  28. {keyboard.close();}
  29. else
  30. {
  31. while (EndOfFile != 'Z'|| EndOfFile !='z' || EndOfFile !='d'|| EndOfFile !='D' )
  32. {
  33. {System.out.print("Or Enter X1 : "); //1
  34. double X1 = keyboard.nextDouble();
  35. System.out.print("Enter Y1 : "); //2
  36. double Y1 = keyboard.nextDouble();
  37. System.out.print("Enter X2 : "); //3
  38. double X2 = keyboard.nextDouble();
  39. System.out.print("Enter Y2 : "); //4
  40. double Y2 = keyboard.nextDouble();
  41. X = (X2-X1);
  42. Y = (Y2-Y1);
  43. x2 = (X*X);
  44. y2 = (Y*Y);
  45. Distance = (x2)+(y2);
  46. Distance = Math.sqrt(Distance);
  47. DecimalFormat df = new DecimalFormat("#.######");
  48. System.out.print("The Distance is : "); //2.8 something
  49. System.out.print(df.format(Distance ));
  50. if (Distance < 0 ){
  51. Distance = Distance * -1;}
  52. }
  53. Scanner keyboard2 = new Scanner (System.in); //repeats the program so two distances can be found before ending it on the 3rd repeat.
  54. System.out.print("\nType the end-of-file indicator to terminate\n" +
  55. "On UNIX/Linux/Mac OS X type <Ctrl> d then press Enter\n" +
  56. "On Windows type <Ctrl> z then press Enter ");
  57. String input2 = keyboard2.nextLine();
  58. char EndOfFile2 = input2.charAt(0);
  59. if (EndOfFile2 == 'Z'){ //Should close the program on the 3rd repeat. Instead it errors.
  60. keyboard2.close();
  61. keyboard.close();
  62. }
  63. }
  64. }
  65. return Distance;
  66. }
  67. }
  68.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:3: error: class PointsTest is public, should be declared in a file named PointsTest.java
public class PointsTest
       ^
Main.java:11: error: class Points is public, should be declared in a file named Points.java
public class Points {
       ^
2 errors
stdout
Standard output is empty