SHARE
TWEET

Untitled

a guest May 23rd, 2019 95 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2.  
  3. public class WeddingPresents {
  4.     public static void main(String[] args){
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         int guests = Integer.parseInt(scanner.nextLine());
  8.         int gifts = Integer.parseInt(scanner.nextLine());
  9.  
  10.         double sumA = 0;
  11.         double sumB = 0;
  12.         double sumV = 0;
  13.         double sumG = 0;
  14.         int counterA = 0;
  15.         int counterB = 0;
  16.         int counterV = 0;
  17.         int counterG = 0;
  18.         for (int i = 0; i < gifts; i++) {
  19.             String giftsCategory = scanner.nextLine();
  20.  
  21.             if (giftsCategory.equals("A")) {
  22.                 counterA++;
  23.                 sumA = (counterA / gifts) * 100;
  24.             } else if (giftsCategory.equals("B")) {
  25.                 counterB++;
  26.                 sumB = (counterB / gifts) * 100;
  27.             } else if (giftsCategory.equals("V")) {
  28.                 counterV++;
  29.                 sumV = (counterV / gifts) * 100;
  30.             } else {
  31.                 counterG++;
  32.                 sumG = (counterG / gifts) * 100;
  33.             }
  34.         }
  35.  
  36.         double percentGifts = gifts / guests * 100;
  37.  
  38.         System.out.printf("%.2f%%%n",sumA);
  39.         System.out.printf("%.2f%%%n",sumB);
  40.         System.out.printf("%.2f%%%n",sumV);
  41.         System.out.printf("%.2f%%%n",sumG);
  42.         System.out.printf("%.2f%%",percentGifts);
  43.     }
  44. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top