Why is not the System.out.println that is in the while printed on the console?

0
package Ejercicio15;

public class AcumuladorInteractivo {
private double nota;

//GET AND SET

public double getNota() {
    return nota;
}
public void setNota(double nota) {
    this.nota = nota;
}

//METODOS

public double media(double nota) {
    double nuevaNota = 0;
    double notaTotal = 0;
    do {
        System.out.println("Introduce un numero: ");
        notaTotal = notaTotal + nota; 
        nuevaNota++;
    }while(nota <= 0);
    return notaTotal/nuevaNota;
}
}

Class with main method

package Ejercicio15;
import java.util.*;
public class AcumuladorInteractivoApp {
   public static void main(String[]args) {
      AcumuladorInteractivo a = new AcumuladorInteractivo();
      Scanner sc = new Scanner(System.in);
      a.media(sc.nextDouble());
      sc.close();
 }
}
    
asked by Vampy95 15.11.2017 в 17:01
source

1 answer

3

The following statement in your loop:

System.out.println("Introduce un numero: ");

... occurs after of the execution of the following statement in your main :

sc.nextDouble()

So the console is waiting for you to enter a number before that you print the message asking for it.

You can check this by entering a number + ENTER, and you will see how the message appears. Obviously, you have a logic problem in your program (actually you have more than one problem in your program). You will have to reorder your sentences properly.

    
answered by 15.11.2017 / 17:06
source