desislava_topuzakova

08. Beer Kegs

May 29th, 2021
1,354
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.00 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class elevator {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         //1. input -> model, radius, height
  7.         //2. volume per keg = π * r^2 * h
  8.         //3. max volume
  9.         int countKegs = Integer.parseInt(scanner.nextLine());
  10.         double maxVolume = Double.MIN_VALUE;
  11.         String maxModel = "";
  12.         for (int keg = 1; keg <= countKegs; keg++) {
  13.             String model = scanner.nextLine(); //модел на кега
  14.             double radius = Double.parseDouble(scanner.nextLine());//радиус
  15.             int height = Integer.parseInt(scanner.nextLine()); //височина
  16.  
  17.             double volume = Math.PI * Math.pow(radius, 2) * height;
  18.             //проверка дали обемът е макс
  19.             if(volume > maxVolume) {
  20.                 maxVolume = volume;
  21.                 maxModel = model;
  22.             }
  23.         }
  24.  
  25.         System.out.println(maxModel);
  26.     }
  27. }
  28.  
Advertisement
Add Comment
Please, Sign In to add comment