I recently started using Java,and I need to start on a big project,but I'm getting weird issues in my code which looks like this:
import java.util.Scanner;
public class Sifre {
public static void main(String[] args) {
Scanner unos = new Scanner(System.in);
System.out.println("Unesite broj sifara:");
int bsif = unos.nextInt();
String sifre[] = new String [bsif];
String imena[] = new String [bsif];
int i,z;
for (i = 0;i<bsif;i++)
{
System.out.println("Unesite sifru broj " + (i+1));
sifre[i] = unos.nextLine();
}
for (z=0;z<bsif;z++)
{
System.out.println(sifre[z]);
}
}
}
Every time I run the code,It skips the first input step and continues to work normally even if the counter starts with more than 0.Here is the output,tell me what is wrong(I know the code isnt perfect,but its my first time posting after 3 months of Java)
> Unesite broj sifara:
>>3
>Unesite sifru broj 1
>Unesite sifru broj 2
>>first
>Unesite sifru broj 3
>>second
>
>first
>
>second