I'm having a problem with this code. I want to make the user answer "yes", then ask for a number. The problem is that by asking again "More data?" it does not let you enter the string again and does not repeat the while again.
My code:
import java.util.*;
public class MaximoLibro {
public static void main(String[]args){
int max = Integer.MIN_VALUE; // es el Low Value
int dato;
boolean hubo = false;
String resp;
Scanner input = new Scanner(System.in);
System.out.println("Quiere ingresar algo?");
resp = input.nextLine();
while (resp.equals("si")){
hubo = true;
System.out.println("Ingrese dato");
dato = input.nextInt();
if (dato > max){
max = dato;
}
System.out.println("Mas datos?");
resp = input.nextLine();
}
if (hubo){
System.out.println("Maximo vale "+max);
}
else {
System.out.println("No hubo datos");
}
input.close();
}
}