Good morning, I'm learning Java, I had a problem and I don't know what the solution is... I want to add a certain amount of data (name, address, money) to an arraylist, I do a for loop for this and when executing the Variable reading is not done correctly. When I use nextLine to read variable 0, the program jumps to 1, so I don't enter the amount of information I want Now, when I use next() this doesn't happen, but when I want to enter a space-separated name as data, the same jump is done as if I were using nextLine... does anyone have any recommendations? arrays
my code is not finished since I can't go from here
public static void main(String\[\] args) {
Scanner sc = new Scanner(System.in);
List <Cliente> lista = new ArrayList<Cliente>(); //declaracion y asignacion del ArrayList
Cliente clie = new Cliente();
System.out.println("De la cantidad de cientes a ingresar: ");
int n = sc.nextInt();
for (int i = 0; i < n; i ++) {
//lista.add(new Cliente("nico","ramos ",1,25000));
System.out.println("Al cliente se le asigno un numero de cliente");
clie.setCodigoCliente(i);
System.out.println("Ingrese el nombre del cliente " +i);
String nom;
clie.setNombre(nom = sc.nextLine());
System.out.println("Ingrese la direccion del cliente "+i);
String direccion;
clie.setDireccion(direccion = sc.nextLine());
}
}
public class Cliente {
int codCliente;
String nombre;
String direccion;
double credito;
public Cliente() { }
public Cliente(String nombre, String direccion, double credito) {
// this.codCliente = codCliente;
this.nombre = nombre;
this.direccion = direccion;
this.credito = credito;
}
// Getters and setters omitted for brevity
}