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)
Error on compiling
Please post the link to your code
package challenges; import java.util.Scanner; public class ManmohanOne { public static void main(String args[]) { Scanner scn = new Scanner(System.in); int n = scn.nextInt(); int rows = 1; int nst = 1; int val = 0; while (rows <= n) { if (rows <= 1) { System.out.print(rows); } else { int cst = 1; while (cst <= nst) { // if(cst == 1 || cst == nst) if ((cst > 1) && (cst < nst)) { System.out.print(val); } else { System.out.print(rows - 1); } cst++; } } System.out.println(); rows++; nst++; } scn.close(); } }
there is some problem with compiler
@Hitesh-Kumar-2485183164914830,
https://ide.codingblocks.com/s/220900 Corrected code.
In the given pattern if row number is n (>1), total character is n. First and last character is n-1 and rest are 0.
Thinking about Value to be printed : row number is to be printed each time at the starting of the row and at the end of the row. So, starting of the row is when out cst is 1 and ending of the row when our cst is nst.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.