Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class WeddingPresents {
- public static void main(String[] args){
- Scanner scanner = new Scanner(System.in);
- int guests = Integer.parseInt(scanner.nextLine());
- int gifts = Integer.parseInt(scanner.nextLine());
- double sumA = 0;
- double sumB = 0;
- double sumV = 0;
- double sumG = 0;
- int counterA = 0;
- int counterB = 0;
- int counterV = 0;
- int counterG = 0;
- for (int i = 0; i < gifts; i++) {
- String giftsCategory = scanner.nextLine();
- if (giftsCategory.equals("A")) {
- counterA++;
- sumA = (counterA / gifts) * 100;
- } else if (giftsCategory.equals("B")) {
- counterB++;
- sumB = (counterB / gifts) * 100;
- } else if (giftsCategory.equals("V")) {
- counterV++;
- sumV = (counterV / gifts) * 100;
- } else {
- counterG++;
- sumG = (counterG / gifts) * 100;
- }
- }
- double percentGifts = gifts / guests * 100;
- System.out.printf("%.2f%%%n",sumA);
- System.out.printf("%.2f%%%n",sumB);
- System.out.printf("%.2f%%%n",sumV);
- System.out.printf("%.2f%%%n",sumG);
- System.out.printf("%.2f%%",percentGifts);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement