March 7 2017

Java program to convert miles to kilometers

Java program to convert miles to kilometers

Multiply the number of miles by 1.6 to get kilometers.

Algorithm

  1. Take the input from the user (miles)
  2. Multiply miles by 1.609 and store the values (kilometers)
  3. Display kilometers

Program


package com.answersz;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class JavaConvertMilesToKilometers {

public static void main(String[] args) {

// Java program to convert miles to kilometers

try {

BufferedReader br = new BufferedReader(new InputStreamReader(
System.in));
System.out.println("Enter Miles : ");
double miles = Double.parseDouble(br.readLine());

double kilometers = 1.609 * miles;
System.out.println("Kilometers: " + kilometers);
}

catch (IOException e) {
System.out.println("error in input");
}

}

}

Output

Enter Miles : 
88
Kilometers: 141.59199999999998


Copyright © 2014. All rights reserved.

Posted March 7, 2017 by answersz in category Bluej Java Programs for ICSE Class 10 and 9 Practice

Leave a Comment

Your email address will not be published. Required fields are marked *

*