TheQuack45

/r/DailyProgrammer challenge #138

Sep 27th, 2013
399
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.56 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.lang.String;
  3.  
  4. public class mainclass {
  5.     public static void main (String[] args){
  6.         Scanner myScanner = new Scanner(System.in);
  7.        
  8.         // Declaration of variables
  9.         float x1; // Particle one's X location
  10.         float y1; // Particle one's Y location
  11.         float x2; // Particle two's X location
  12.         float y2; // Particle two's Y location
  13.         float deltaX; // Change in the X value between particle one and particle two
  14.         float deltaY; // Change in the Y value between particle one and particle two
  15.         float mass1; // Mass of particle one
  16.         float mass2; // Mass of particle two
  17.         float distance; // square-root(deltaX * deltaX + deltaY * deltaY)
  18.         float force; // (mass1 * mass2) / (distance * distance)
  19.        
  20.         // Variable input for particle 1
  21.         System.out.println("Mass of particle 1");
  22.         mass1 = myScanner.nextFloat();
  23.         System.out.println("X-position of particle 1");
  24.         x1 = myScanner.nextFloat();
  25.         System.out.println("Y-position of particle 1");
  26.         y1 = myScanner.nextFloat();
  27.        
  28.         // Variable input for particle 2
  29.         System.out.println("Mass of particle 2");
  30.         mass2 = myScanner.nextFloat();
  31.         System.out.println("X-position of particle 2");
  32.         x2 = myScanner.nextFloat();
  33.         System.out.println("Y-position of particle 2");
  34.         y2 = myScanner.nextFloat();
  35.        
  36.         // Calculations
  37.         deltaX = (x1 - x2);
  38.         deltaY = (y1 - y2);
  39.         distance = (float) Math.sqrt((deltaX * deltaX) + (deltaY * deltaY));
  40.         force = ((mass1 * mass2) / (distance * distance));
  41.        
  42.         System.out.print("The repulsion force between the two particles is " + force + ".");
  43.     }
  44.  
  45. }
Advertisement
Add Comment
Please, Sign In to add comment