Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.text.DecimalFormat;
- import java.util.Scanner;
- public class BeverageLabels {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- String name = scan.nextLine();
- double volume = Double.parseDouble(scan.nextLine());
- double energyContent = Double.parseDouble(scan.nextLine());
- double sugarContent = Double.parseDouble(scan.nextLine());
- double kcalPerDrink = (energyContent / 100) * volume;
- double sugarPerDrink = (sugarContent / 100) * volume;
- DecimalFormat decimalFormat = new DecimalFormat("#.##");
- System.out.println(String.format("%sml %s:", decimalFormat.format(volume), name));
- System.out.println(String.format("%skcal, %sg sugars",
- decimalFormat.format(kcalPerDrink),
- decimalFormat.format(sugarPerDrink)));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement