Program to convert pounds (lbs) to Kilograms (kg) in Java

Today we are going to write a program to convert weight in pounds to kilograms. As we all know units are not the same everywhere, in some places pounds are used to measure the weight of an object and in some places kilograms are used. hence to equalize the units of weight we need a unit converter.

We all know

1 kg= 2.2046 lb

1 pounds= 0.4536 kg

Program to convert pounds (lbs) to Kilograms (kg) in Java

In this program, we will provide choices to the user to either convert pounds to kg or vice-versa. Similarly, you can make a whole calculator just by adding more cases through a switch case.

Here is the code for same:

import java.util.Scanner;
public class poundstokg {

  public static void main(String[] args) {
  
    Scanner sc=new Scanner (System.in);
    System.out.println("menu\t");
    System.out.println("1. pounds to kg");
    System.out.println("2. kg to pounds");
    int n=sc.nextInt();
    System.out.println("enter data for conversion");
    double d=sc.nextDouble();
    String st="";
    double result=1;
    if(n==1)
      {result=d*0.4536;
        st="kg";}
    else
    {	result=d*2.2046;
        st="lbs";}
    System.out.println("after conversion: "+result+" "+st);
    
      
  }

}

Output:

menu	
1. pounds to kg
2. kg to pounds
1
enter data for conversion
25
after conversion: 11.34 kg

menu	
1. pounds to kg
2. kg to pounds
2
enter data for conversion
25
after conversion: 55.115 lbs

Also, read:

Leave a Reply

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