TOPIC

Presentation Error 5% JAVA

ltorbes asked 2 years ago

alguém me ajudaaaaa

import java.io.IOException; import java.util.Scanner;

public class Main {

public static void main(String[] args) throws IOException {
    Scanner sc = new Scanner(System.in);

    int n;
    int quantia;
    String tipo;
    double total;
    int i;
    int c;
    int r;
    int s;
    double percentualC;
    double percentualR;
    double percentualS;

    n = sc.nextInt();
    total = 0;
    c = 0;
    r = 0;
    s = 0;
    i = 0;
    while (i < n) {
        quantia = sc.nextInt();         
        tipo = sc.next();
        tipo = tipo.toLowerCase();

        if (tipo.equals("c")) {
            c = c + quantia;                
        } else if (tipo.equals("r")) {
            r = r + quantia;                
        } else if (tipo.equals("s")) {
            s = s + quantia;
        }
        total = total + quantia;

        i = i + 1;
    }     
    percentualC = (c / total) * 100;
    percentualR = (r / total) * 100;
    percentualS = (s / total) * 100;

    System.out.println("Total: " + (int)total + " cobaias");
    System.out.println("Total de coelhos: " + c);
    System.out.println("Total de ratos: " + r);
    System.out.println("Total de sapos: " + s);
    System.out.printf("Percentual de coelhos: %.2f %% \n", percentualC);
    System.out.printf("Percentual de ratos: %.2f %% \n", percentualR);
    System.out.printf("Percentual de sapos: %.2f %% \n", percentualS);
}

}

This topic has not been answered yet. Be the first!

Remember not post solutions. Your post may be reviewed by our moderators.