Advertisement
veronikaaa86

Bevarage Labels

Jan 22nd, 2018
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.74 KB | None | 0 0
  1.  
  2. import java.text.DecimalFormat;
  3. import java.util.Scanner;
  4.  
  5. public class P04_BeverageLabels {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.         DecimalFormat df = new DecimalFormat("#.#######");
  9.  
  10.         String name = scanner.nextLine();
  11.         int volume = Integer.parseInt(scanner.nextLine());
  12.         int energy = Integer.parseInt(scanner.nextLine());
  13.         int sugarContent = Integer.parseInt(scanner.nextLine());
  14.  
  15.         double allEnergy = energy / 100.0 * volume;
  16.         double allSugar = sugarContent / 100.0 * volume;
  17.  
  18.         System.out.printf("%dml %s:%n", volume, name);
  19.         System.out.printf("%skcal, %sg sugars", df.format(allEnergy), df.format(allSugar));
  20.     }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement