viewing paste KgToPound | Java

Posted on the
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
//Import Scanner to allow the to input data in the console and have the console read it
import java.util.Scanner;
 
public   class KgToPound{
 
    public   static   void  main(String[] args){      
        
        Scanner scan = new Scanner(System.in);
 
        System.out.print("Please input your weight in kg: ");
        //Initialize variable
        int num_1 = 1;
        //Double variable in case user inputs decimal
        double num_2 = scan.nextDouble();
        //Message
        System.out.println("Kilograms\t|\tPound");
 
            //Fun little loop to compute the weight from 0 to given kg
            while(num_1 <= num_2){
                double variable = num_1*2.2;
         
                System.out.printf("%d\t|\t%10.3f\n",num_1,variable);
         
                num_1++;
         
            }
            
        //Compute final result of actual weight
        double result = num_2*2.2;
        //Message with result
        System.out.printf("%4.2f kg is equal to %4.3f pound\n",num_2,result);
         
   }
 
}
Viewed 1525 times, submitted by Streusel.