How can I make the while work for me?

1

It does not work directly for me, it does not print anything, I can not find the error. The statement of the program is as follows:

Given the grades and names of students in a course, print the names of students whose grade is greater than 7. The entry ends when a negative note is entered .

 String nombre;
 int nota = 0;

 Scanner teclado = new Scanner (System.in);


 while(nota<0) {
     System.out.println("Ingrese nombre : ");
     nombre = teclado.next();
     System.out.println("Ingrese nota : ");
     nota=teclado.nextInt();
     if(nota>7) {
         nota = teclado.nextInt();

         System.out.println("Alumno con nota mayor a 7 : " +nombre );
     }

 }
    
asked by computer96 16.08.2018 в 15:05
source

1 answer

0

Let's see ... you have several bad concepts. First, you will never enter the while cycle because you notice that the condition that you are passing is that the note is less than zero, which will never be if you said above that the note is equal to 0 !!!

Try this code and analyze it:

public static void main(String[] args) {

  String nombre; 
  int nota = 0;

  Scanner teclado = new Scanner (System.in);

  while(nota >= 0) {
      System.out.println("Ingrese nombre : ");
      nombre = teclado.nextLine();
      System.out.println("Ingrese nota : ");
      nota = teclado.nextInt();

      if(nota > 7) {
          System.out.println("Alumno con nota mayor a 7 : " + nombre );
      }
      else{
          System.out.println("Alumno reprobado con nota menor a 7: " + nombre);
      }
  }   
}
    
answered by 16.08.2018 / 15:13
source