Good, I need it to detect that if I don't write anything in the scanner and I hit enter without further ado, I skip this message indicating that I must write something.
As if it were a mandatory field but I don't know why it doesn't jump out to me with this.
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String nombreIntroducido = "";
System.out.println("Introduzca nombre de empleado");
nombreIntroducido = scanner.next();
if(nombreIntroducido.isEmpty()) {
System.out.println("Escribe algo porfavor");
}else {
nombreIntroducido = scanner.next();
}
}
Is something like this what you are looking for?
The program will not let you pass and will ask you for the name of the employee infinitely if the name is empty.
This is because the while that checks if the name is empty will continue doing the loop
Hello, I hope this will also help you, it enters the loop through the "do" and keeps waiting for the entered string to not be empty, due to the "while" condition.