I'm encountering problems with this snippet of code:
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
String risposta;
System.out.println("Quanti conti vuoi creare?\n");
int numero_conti = in.nextInt();
CCB[] conti = new CCB[numero_conti + 1];
for (int i = 1; i <= numero_conti; i++)
{
conti[i] = new CCB();
System.out.println("CONTO " + i + "\n");
System.out.println("Banca: ");
conti[i].setBanca(in.nextLine());
System.out.println("Sede: ");
conti[i].setSede(in.nextLine());
System.out.println("Nome: ");
conti[i].setNome(in.nextLine());
System.out.println("Cognome: ");
conti[i].setCognome(in.nextLine());
System.out.println("Codice Fiscale: ");
conti[i].setCodice_fiscale(in.nextLine());
System.out.println("Numero di conto corrente: ");
conti[i].setNumero_conto(in.nextInt());
System.out.println("Saldo: ");
conti[i].setSaldo(in.nextDouble());
}
The output is the following:
Quanti conti vuoi creare?
1
CONTO 1
Banca:
Sede:
>input here<
The problem is as follows:
In the code "snippet" the for loop does not work well. It should show me in output every single input after every System.out. But the result is that instead of inserting 7 inputs, I can insert only 6 and the first two System.out are attached together.
How can I solve this problem?
I tried in every way. If I insert only next (); I can not insert multiple strings followed by space all at once.
The output I would like should be the following:
Quanti conti vuoi creare?
1
CONTO 1
Banca:>Input here<
Sede: >Input here<
Please help me to solve this! Thank you!