Advertisement
Guest User

Teach me java

a guest
Jul 19th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.03 KB | None | 0 0
  1. package package_3;
  2. import static java.lang.System.out;
  3. import java.util.Scanner;
  4. public class Main {
  5.  
  6.     public static void main(String[] args) {
  7.    
  8.         poundToKilo();
  9.     }
  10.     /*
  11.      * This program asks from the user for weight in pound, converts
  12.      * the input to kilo, then displays the result in various precisions.
  13.      */
  14.     static void poundToKilo()
  15.     {
  16.         //"final" keyword prevents the variable from being modified
  17.         final double KILO_PER_POUND = 0.4536;
  18.         double weightInPound;//for storing user input
  19.         try(Scanner input = new Scanner(System.in))
  20.         {
  21.             out.print("Enter weight in pound: ");
  22.             weightInPound = input.nextDouble();
  23.         }
  24.         //Data processing
  25.         double kilo = weightInPound * KILO_PER_POUND;
  26.         //Display the result in difference precisions
  27.         out.printf("Default roundup: %f\n", kilo);
  28.         out.printf("Round up to 2 points: %-10.2f\n", kilo);
  29.         out.printf("Round up to 3 points: %10.3f\n", kilo);
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement