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