Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a Java program by String Class that asks the user to enter distance in Kil

ID: 3885376 • Letter: W

Question

Write a Java program by String Class that asks the user to enter distance in Kilometers. The program then computes the distance in Miles using the following formula: Miles = 0.621371 × Kilometers The program should display the distance in Kilometers and Miles as follows: Distance: 100 Kilometers = 62.1371 Miles

A properly documented source code (.java files) (Do not need to add a comment in each line, but you must explain the code appropriately). At the start of the code, identify the student number and name, and also state the question number and date.  

Explanation / Answer

import java.util.*;

public class km_miles{

public static void main(String args[]){

Scanner in=new Scanner(System.in);

int n=in.nextInt();

double miles=0.621371*n;

System.out.println("Distance : "+n+" Kilometers = "+String.format("%.4f",miles)+" Miles");

}

}

String.format is used to display only four digits after the decimal point

output:

100
Distance : 100 Kilometers = 62.1371 Miles

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote