Computer Science, asked by Zafar9713, 10 months ago

An athlete takes 18 rounds of a triangular park with sides 30,25,35 in metres.Write a java program to determine the total distance covered by him

Answers

Answered by poojan
22

The code is completely written concentrating on dynamic nature. Based on the input, the result will be generated. It means, you can calculate the distance covered with different lengths of a side too.

Note :

I have attached the program and it's compilation, with the output as an attachment. Have a look at it. I have compiled the code on java editor, and the code is perfect!

Program :

import java.util.Scanner;

public class Distancecovered

{

   public static void main(String[] args)

   {

     Scanner sc= new Scanner(System.in);

     System.out.println("Enter total no.of rounds taken :");

     int rounds = sc.nextInt();

     System.out.println("Enter side 1's length in meters :");

     int side1 = sc.nextInt();

     System.out.println("Enter side 2's length in meters :");

     int side2 = sc.nextInt();

     System.out.println("Enter side 3's length in meters :");

     int side3 = sc.nextInt();

     int PerimeterOfTriangle=side1+side2+side3;

     int TotalDistance=rounds*PerimeterOfTriangle;

     System.out.println("Total distance covered is : "+TotalDistance+" meters.");      

   }

}

Input :

Enter total no.of rounds taken :  18

Enter side 1's length in meters :  30

Enter side 2's length in meters :  25

Enter side 3's length in meters : 35

Output :

Total distance covered is : 1620 meters.

Explanation :

As the park is triangular, it has three sides and each side will have a certain size. Considering the units in meters, we will be taking the three inputs of three sides corresponding sizes. And another input will be of the no.of rounds a man takes, around the rectangular park.

The distance covered by the man in one round, will be the perimeter of the park. And the perimeter of a triangle is the sum of their sides. On summing up the sizes of the sides inputted, we will get the distance covered by a man taking one round. For n rounds, it will be n*perimeter units. That's it! There you go!

Hope it helps. If yes, leave a smile. :)

Attachments:
Answered by bhumi996
3

Answer-

java programming

.

.

.

.

public class Calc {

void distance ()

{

int side1=25;

int side2=30;

int side3=35;

int One_round=0;

int dist=0;

One_round=side1+side2+side3;

dist=One_round*18;

System.out.println("Total distance covered (in meters):"+dist); (Note:it's in one line don't do it in another line.I have no spc)

}

}

Similar questions