This is my code:
import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner scn = new Scanner(System.in);
int n = scn.nextInt();
int num1=0;
int num2=1;
int row=1;
while(row<=n){
for(int cst=1;cst<=row;cst++){
int f;
System.out.print( num1 +"\t");
f = num1;
num1=num2;
num2 = num2+f;
cst++;
}
row++;
}
}
}
On compilation it shows the error:
Exception in thread “main” java.util.NoSuchElementException
at java.util.Scanner.throwFor(Scanner.java:862)
at java.util.Scanner.next(Scanner.java:1485)
at java.util.Scanner.nextInt(Scanner.java:2117)
at java.util.Scanner.nextInt(Scanner.java:2076)
at Main.main(Main.java:5)
I used the scanner the same way in all the pattern related lectures. How do i resolve this error?