EduLearn - Online Education Platform

Welcome to EduLearn!

Start learning today with our wide range of courses taught by industry experts. Gain new skills, advance your career, or explore new interests.

Browse Courses

Distance between 2 cities are input through the keyboard. Write a java programs and print this distance in metre, cm, feet and inches

Here’s a simple Java program that:

 

1. Takes the distance between two cities in kilometers as input.

 

 

2. Converts and prints it in:

 

Meters

 

Centimeters

 

Feet

 

Inches

 

 

 

 

import java.util.Scanner;

 

public class DistanceConverter {

public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);

 

// Input distance in kilometers

System.out.print(“Enter distance between two cities (in kilometers): “);

double kilometers = scanner.nextDouble();

 

// Convert to other units

double meters = kilometers * 1000;

double centimeters = meters * 100;

double feet = meters * 3.28084;

double inches = feet * 12;

 

// Output results

System.out.println(“Distance in meters: ” + meters);

System.out.println(“Distance in centimeters: ” + centimeters);

System.out.println(“Distance in feet: ” + feet);

System.out.println(“Distance in inches: ” + inches);

 

scanner.close();

}

}

 

Example Output

 

Enter distance between two cities (in kilometers): 5

Distance in meters: 5000.0

Distance in centimeters: 500000.0

Distance in feet: 16404.199999999999

Distance in inches: 196850.4

 

 

Java

Leave a Reply

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

EduLearn - Online Education Platform

Welcome to EduLearn!

Start learning today with our wide range of courses taught by industry experts. Gain new skills, advance your career, or explore new interests.

Browse Courses

Popular Courses

[Course Image]

Introduction to Programming

Learn the fundamentals of programming with Python in this beginner-friendly course.

12 Hours Beginner
[Course Image]

Data Science Essentials

Master the basics of data analysis, visualization, and machine learning.

20 Hours Intermediate
[Course Image]

Web Development Bootcamp

Build modern websites with HTML, CSS, JavaScript and popular frameworks.

30 Hours Beginner
[Course Image]

Digital Marketing Fundamentals

Learn SEO, social media marketing, email campaigns and analytics.

15 Hours Beginner
Educational Website Footer