(URI) Tipo de Combustível - Solução

import java.io.*;
import java.util.*;

class Main  {
    public static void main(String[] args) throws NumberFormatException, IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
       
        int valor = leitor(br);

        int alcool = 0;
        int gasolina = 0;
        int diesel = 0;       
        while (valor != 4) {
            switch(valor) {
                case 1:
                    alcool++;
                    break;
                case 2:
                    gasolina++;
                    break;
                case 3:
                    diesel++;
                    break;
                default:
                    break;
            }
           
            valor = leitor(br);       
        }

        System.out.println("MUITO OBRIGADO\nAlcool: " + alcool + "\nGasolina: " + gasolina + "\nDiesel: " + diesel);
    }

    static int leitor(BufferedReader br) throws NumberFormatException, IOException {
       int n;
       int resp = 0;

       while (true) {
           n = br.read();
           if (n >= '0' && n <= '9') break;

       }
       while (true) {
           resp = resp*10 + n-'0';
           n = br.read();
           if (n < '0' || n > '9') break;
       }

       return resp;
    }
}

Comments

Popular posts from this blog

(Coderbyte) Dash Insert II - Solução

(Coderbyte) Run Length - Solução

(Coderbyte) Counting Minutes I - Solução