TOPIC

Wrong answer (15%) Alguém me salva por favor!

meduarda108 asked 3 years ago

No meu netbeans o programa funciona da forma que o uri pede mas quando eu envio fica dando erro de 15% alguém me da uma luz fazendo favor hahaha

Scanner input = new Scanner(System.in); int horaInicial = input.nextInt(); int horaFinal = input.nextInt(); int total;

    if (horaInicial > horaFinal) {
        total = (24 - horaInicial) + horaFinal;
        System.out.println("O JOGO DUROU " + total + " HORA(S)");

    } else if (horaInicial < horaFinal) {
        total = horaFinal - horaInicial;
        System.out.println("O JOGO DUROU " + total + " HORA(S)");

    } else if(horaInicial == 0 && horaFinal==0){
        System.out.println("O JOGO DUROU 24 HORA(S)");
    }

This topic was solved and cannot recieve new replies.

  • josean replied 3 years ago

    if (horaInicial > horaFinal) { total = (24 - horaInicial) + horaFinal; System.out.println("O JOGO DUROU " + total + " HORA(S)");

    }

    substitua por

    if (horaInicial > horaFinal) { total = (horaFinal - horaInicial) + 24; System.out.println("O JOGO DUROU " + total + " HORA(S)");

    }

  • josean replied 3 years ago

    Boa noite Maria Eduarda. Faltou o caso de teste caso as horas sejam iguais, quando isso acontece significa que se passou 24 horas, fiz essa alteração e funcionou aqui.

    CODIGO:

    import java.util.Scanner;

    public class Main { public static void main(String[] args) { Scanner input = new Scanner(System.in); int horaInicial = input.nextInt(); int horaFinal = input.nextInt(); int total;

      if (horaInicial > horaFinal) {
         total = horaFinal - horaInicial + 24;
         System.out.println("O JOGO DUROU " + total + " HORA(S)");
      }else if (horaInicial < horaFinal) {
        total = horaFinal - horaInicial;
        System.out.println("O JOGO DUROU " + total + " HORA(S)");
    
      }else if(horaInicial == horaFinal){
        System.out.println("O JOGO DUROU 24 HORA(S)");
      }

    } }

  • meduarda108 replied 3 years ago

    Pessoal fiz a alteração que o Josean falou e mesmo assim o erro ainda continua acontecendo...