I'm new to this forum,hope that my code will display below. I am doing my first program with scanners and converting values, i started off with integers but that was not realistic so i changed to double however the output
import java.util.Scanner;
public class Milestokm {
public static void main(String[] args) {
//Converting Miles to Kilometers
final double MILES_TO_KM = 1.60935;
double answer;
//Scanner to creates method to read input
Scanner scan = new Scanner(System.in);
double miles;
//Input
System.out.println("Enter the number of miles:");
miles = scan.nextDouble();
// calculate Miles to KM
answer = miles * MILES_TO_KM;
// output
System.out.println("The number of miles: " +miles+ " M converted to kilometers = " + answer +"km");
the output shows way too many decimal places, is there an simple way of getting 2 decimal places?

New Topic/Question
Reply




MultiQuote



|