Java Program || Write a Java program to enter length in centimeter and convert it into meter and kilometer.
Write a Java program to enter length in centimeter and convert it into meter and kilometer.
Solution :-
meter = cm / 100.0;
km = cm / 100000.0;
Static :-
class convert
{
public static void main(String args[])
{
double cm=1000,meter,km;
meter = cm/100.0;
km = cm/100000.0;
System.out.println("The meter :-"+meter);
System.out.println("The Kilometer is :-"+km);
}
}
Output :-
Dynamic :-
import java.util.*;
class convert
{
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
System.out.println("Enter the cm :- ");
int cm = in.nextInt();
double meter = cm/1000.0;
double km = cm/100000.0;
System.out.println("The meter :-"+meter);
System.out.println("The Kilometer is :-"+km);
}
}
Output :-