211k views
0 votes
One lap around a standard high-school running track is exactly 0.25 miles. Write a program that takes a number of miles as input, and outputs the number of laps. Output each floating-point value with two digits after the decimal point, which can be achieved as follows: System.out.printf("%.2f", yourValue); Ex: If the input is:

User Ashansky
by
5.1k points

2 Answers

4 votes

Answer:

def miles_to_laps(miles):

return miles / 0.25

miles = 5.2

num_of_lap = miles_to_laps(miles)

print("Number of laps for %0.2f miles is %0.2f lap(s)" % (miles, num_of_lap))

Step-by-step explanation:

User Eddinho
by
5.9k points
1 vote

Answer:

import java.util.Scanner;

public class Miles {

public static void main(String[] args) {

//initialization

double Number_Miles;

//print the message

System.out.print("Enter the number of miles: ");

Scanner scn1 = new Scanner(System.in);

Number_Miles = scn1.nextDouble(); //read the input from user

//calculate the laps

double yourValue = Number_Miles/0.25;

//display the output on the screen

System.out.printf("%.2f", yourValue);

}

}

Step-by-step explanation:

First import the library Scanner than create the class and define the main function. In the main function, declare the variables.

print the message on the screen and then store the value enter by the user into the variable.

Scanner is a class that is used for reading the output. So, we make the object of the class Scanner and then object call the function nextDouble() which reads the input and store in the variable.

After that, calculate the number of laps by dividing the number of miles with the given one lap running track value (0.25 miles).


Number\,of\,laps = (Number\,of\,miles)/(0.25)

the output is stored in the variable.

After that, print the value on the screen with 2 digits after the decimal point.

we can use "%.2f" in the printing function in java.

like System.out.printf("%.2f", output);

User Mikeagg
by
4.9k points