TheBulgarianWolf

Beer Keg Comparison

Apr 23rd, 2020
397
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.07 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class SoftUni {
  4.  
  5.     public static void main(String[] args) {
  6.         Scanner sc = new Scanner(System.in);
  7.         System.out.print("Enter the number of kegs you want to enter(1-10): ");
  8.         String biggestKeg = "";
  9.         double currentKegVolume = 0.0;
  10.         int n = Integer.parseInt(sc.nextLine());
  11.         for(int i = 0;i < n;i++){
  12.             System.out.print("Model of keg number " + (i+1) + " is: " );
  13.             String model = sc.nextLine();
  14.             System.out.print("The radius of keg number " + (i+1) + " is: ");
  15.             double radius = Double.parseDouble(sc.nextLine());
  16.             System.out.print("The height of keg number " + (i+1) + " is: ");
  17.             double height = Double.parseDouble(sc.nextLine());
  18.             double volume = radius*radius*height*Math.PI;
  19.             if(volume > currentKegVolume){
  20.                 currentKegVolume = volume;
  21.                 biggestKeg = model;
  22.             }
  23.         }
  24.        
  25.         System.out.println("The biggest keg is: " + biggestKeg);
  26.        
  27.     }
  28.  
  29. }
Add Comment
Please, Sign In to add comment