Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class ex9d
- {
- public static void main(String[] args)
- {
- Scanner input = new Scanner(System.in);
- int option = 0;
- char c;
- do
- {
- System.out.print("***** Kilogram / Pound Converter *****\n\n***** [1] Kilogram to Pound : \n***** [2] Pound to Kilogram : ");
- option = input.nextInt();
- switch(option)
- {
- case 1:
- System.out.print("Please enter a Kilogram Value : ");
- double a = input.nextDouble();
- System.out.print(a + " Kilograms converted to pounds is " + convertKilostoPounds(a));
- break;
- case 2:
- System.out.print("Please enter a Pound Value : ");
- double b = input.nextDouble();
- System.out.print(b + " Kilograms converted to pounds is " + convertPoundstoKilos(b));
- break;
- default:
- System.out.print("Incorect Option");
- }
- System.out.print("\nWould you like to convert another value y/n? : ");
- c = input.next().charAt(0);
- }
- while( c == 'y' || c == 'Y' );
- }
- public static double convertKilostoPounds(double a)
- {
- double i = a * 2.2;
- return Math.round(i * 100.0 ) / 100.0;
- }
- public static double convertPoundstoKilos(double a)
- {
- double kilos = a / 2.2;
- return Math.round(kilos * 100.0 ) / 100.0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement