97.7k views
0 votes
A pedometer treats walking 2,000 steps as walking 1 mile. Write a program whose input is the number of steps, and whose output is the miles walked. Output each floating-point value with two digits after the decimal point, which can be achieved as follows: printf("%0.2lf", yourValue);

User Dan Ganiev
by
4.8k points

1 Answer

2 votes

Answer:

import java.util.Scanner;

public class num1 {

public static void main(String[] args) {

Scanner in = new Scanner(System.in);

//Prompt and receive user input

System.out.println("Enter number of Steps");

int numSteps = in.nextInt();

double numMiles = numSteps/2000;

//Print the formated number of miles

System.out.printf("The equivalent miles is %.2f ",numMiles);

}

}

Step-by-step explanation:

  • This is solved using Java programming language
  • Scanner class is imported and used to receive user input (number of steps walked)
  • To convert number of steps to number of miles, we divide by 2000, Since the question says the pedometer treats walking 2,000 steps as walking 1 mile.
  • Output the number of miles to 2 decimal places using java's printf() method
User NOlivNeto
by
5.4k points