Java Function that converts inches to centimetre.

//Java Function that converts inches to centimetre.


import java.util.Scanner;

public class Program 
{   
    	public static void main( String[] args ) 
    	{
		Scanner reader = new Scanner(System.in);
		float inch,cm;
		System.out.print("\nEnter value in Inch : ");
		inch = reader.nextInt();
		cm=convert(inch);
		System.out.print(inch +" inch is equal to "+ cm +" centimeter ");
    	}

    	public static float convert(float a)
    	{
		float cm1;
		cm1 = (float)(a*2.54);
		return cm1;
    	}
}

Output :
Enter value in Inch : 50

50.00 inch is equal to 127.00 centimeter



Leave a comment