i am running a code for one of the challenges , on my eclipse app that i have in my laptop its running properly , but on coding blocks IDE its giving me an error, please help
the code is
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
System.out.print("Enter the no. of rows : ");
Scanner scn = new Scanner(System.in);
int n = scn.nextInt();
int row = 1;
int nst = 1;
int nsp1 = n - 1;
int nsp2 = -1;
int val1 = row;
int val2 = 1;
while (row <= n) {
int csp1 = 1;
while (csp1 <= nsp1) {
System.out.print(" ");
csp1 = csp1 + 1;
}
int cst1 = 1;
while (cst1 <= nst) {
System.out.print(val1 + " ");
val1 = val1 - 1;
cst1 = cst1 + 1;
}
int csp2 = 1;
while (csp2 <= nsp2) {
System.out.print(" ");
csp2 = csp2 + 1;
}
if (row != 1 && row != n) {
int cst2 = 1;
while (cst2 <= nst) {
System.out.print(val2 + " ");
val2 = val2 + 1;
cst2 = cst2 + 1;
}
}
System.out.println();
if (row <= n / 2) {
nst = nst + 1;
nsp1 = nsp1 - 2;
nsp2 = nsp2 + 2;
val1 = row + 1;
val2 = 1;
}
else {
nst = nst - 1;
nsp1 = nsp1 + 2;
nsp2 = nsp2 - 2;
val1 = n - row;
val2 = 1;
}
row = row + 1;
}
}
}
and the error is
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:6)
please help me with this problem i am unable to submit my codes