Advertisement
Lyubohd

Untitled

Sep 21st, 2017
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.88 KB | None | 0 0
  1. import java.text.DecimalFormat;
  2. import java.util.Scanner;
  3.  
  4. public class BeverageLabels {
  5.     public static void main(String[] args) {
  6.         Scanner scan = new Scanner(System.in);
  7.  
  8.         String name = scan.nextLine();
  9.         double volume = Double.parseDouble(scan.nextLine());
  10.         double energyContent = Double.parseDouble(scan.nextLine());
  11.         double sugarContent = Double.parseDouble(scan.nextLine());
  12.  
  13.         double kcalPerDrink = (energyContent / 100) * volume;
  14.         double sugarPerDrink = (sugarContent / 100) * volume;
  15.  
  16.         DecimalFormat decimalFormat = new DecimalFormat("#.##");
  17.  
  18.         System.out.println(String.format("%sml %s:", decimalFormat.format(volume), name));
  19.         System.out.println(String.format("%skcal, %sg sugars",
  20.                 decimalFormat.format(kcalPerDrink),
  21.                 decimalFormat.format(sugarPerDrink)));
  22.     }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement