Computer Science, asked by shivangsingh492, 1 month ago

Write a program in Java to input mass and acceleration and then calculate and display the force.

Answers

Answered by anindyaadhikari13
3

\textsf{\large{\underline{Solution}:}}

The given problem is solved using language - Java.

import java.util.Scanner;

public class Java{

   public static void main(String args[]){

       Scanner sc=new Scanner(System.in);

       double mass,acceleration,force;

       System.out.print("Enter mass - ");

       mass=sc.nextDouble();

       System.out.print("Enter acceleration - ");

       acceleration=sc.nextDouble();

       force=mass*acceleration;

       System.out.println("Force: "+force+" N.");

       sc.close();

   }

}

\textsf{\large{\underline{Logic}:}}

  • Accept force and acceleration from the user.
  • Multiply force and acceleration and store the result in variable 'force'.
  • Display the 'force'.

See attachment for output.

Attachments:
Answered by kamalrajatjoshi94
1

Answer:

Program:-

import java.util.*;

public class Main

{

public static void main(String args[])

{

Scanner in=new Scanner(System.in);

double m,a,f=0;

System.out.println("Enter the mass :");

m=in.nextDouble();

System.out.println("Enter acceleration or retardation");

a=in.nextDouble();

if(a>0)

{

f=m*a;

System.out.println("The force in the direction of force:"+f+"N");

}

else if(a<0)

{

f=m*a;

System.out.println("The force opposite in the direction of force:"+f+"N");

}

else if(a==0)

System.out.println("The force is 0N");

}

}

Formula:-

F=ma

Logic:-

  • Negative acceleration is called retardation. So for this case it is in the opposite in the direction of force otherwise it is in the direction of force.
Attachments:
Similar questions