How to create a "want to continue" Java Nide question

Asked

Viewed 66 times

-1

public void nfinal(){
       double n1, n2;
       System.out.println("Digite o valor da nota 1 e da nota 2: ");
       n1 = ler.nextDouble();
       n2 = ler.nextDouble();
      
       double nf = (n1+n2)/2;
       System.out.printf("Nota final = %1en", nf);
       
       if(nf < 6){
         System.out.println("Reprovado.");
         
       }else{
         System.out.println("Aprovado.");
       }
} 

I’ve been trying to ask a question deseja continuar?, but none of my attempts work.

Could you help me?

1 answer

1

Try something like that:

 Scanner ler = new Scanner(System.in);
    String answer = "";
    do {
        double n1, n2;
        System.out.println("Digite o valor da nota 1 e da nota 2: ");
        n1 = ler.nextDouble();
        n2 = ler.nextDouble();

        double nf = (n1 + n2) / 2;
        System.out.printf("Nota final = %.2f \n", nf);

        if (nf < 6) {
            System.out.println("Reprovado.");

        } else {
            System.out.println("Aprovado.");
        }
        System.out.println();
        System.out.println("Deseja continuar (sim/nao)?");
        answer = ler.next();
        System.out.println();

    } while (answer.equalsIgnoreCase("sim"));

Browser other questions tagged

You are not signed in. Login or sign up in order to post.