Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package reddit.Challenges.Challenge138;
- import java.util.Scanner;
- public class Challenge138 {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- String data1 = sc.nextLine();
- Particle particle1 = new Particle(data1);
- String data2 = sc.nextLine();
- Particle particle2 = new Particle(data2);
- float deltaX = particle2.getX() - particle1.getX();
- float deltaY = particle2.getY() - particle1.getY();
- double distance = Math.sqrt(deltaX*deltaX + deltaY*deltaY);
- double force = (particle1.getMass() * particle2.getMass())/(distance*distance);
- System.out.println("Force between particles: " + force);
- sc.close();
- }
- }
- public class Particle {
- public Particle(String data) {
- Scanner sc = new Scanner(data);
- sc.useDelimiter(" ");
- float mass = sc.nextFloat();
- float x = sc.nextFloat();
- float y = sc.nextFloat();
- this.setMass(mass);
- this.setX(x);
- this.setY(y);
- }
- public float getX() {
- return x;
- }
- public void setX(float x) {
- this.x = x;
- }
- public float getY() {
- return y;
- }
- public void setY(float y) {
- this.y = y;
- }
- public float getMass() {
- return mass;
- }
- public void setMass(float mass) {
- this.mass = mass;
- }
- private float x;
- private float y;
- private float mass;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement