
Write a class that contains the following two methods:
/* converts from inches to centimeters */ Public static double inchToCentimeter(double in)
/* converts from centimeters to inches */ Public static double CentimetertoInches (double cm)
The formula for the conversion is: inches = 2.54 * centimeters
Write a program that invokes these methods to display the following table:
Inches Centimeters Centimeters Inches 1.0 2.54 5.0 1.96 2.0 5.08 10.0 3.93 �� 10.0 25.4 50.0 19.68

import java.text.*;
class Conversion
{
public static double inchtoCentimetre(double inch){
double cm = inch * 2.54;
return cm;
}
public static double centimetertoInch(double cm){
double inch=cm/2.54;
return inch;
}
public static void main(String[] args)
{
DecimalFormat df=new DecimalFormat("##.##");
System.out.println("Inches Centimeters");
double inch[]={1,2,5};
double cms[]={5,10,50};
for(int i=0;i<inch.length;i++){
double cm = inchtoCentimetre(inch[i]);
System.out.println(inch[i]+"\t "+df.format(cm));
}
System.out.println("Centimeters Inches");
for(int i=0;i<cms.length;i++){
double in = centimetertoInch(cms[i]);
System.out.println(cms[i]+" \t "+df.format(in));
}
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.