+ 2
Need help with Java.
I made a program to print patterns composed of stars. I'm getting the following error: Exception in thread "main" java.util.NoSuchElementException at java.util.Scanner.throwFor(Unknown Source) at java.util.Scanner.next(Unknown Source) at java.util.Scanner.nextInt(Unknown Source) at java.util.Scanner.nextInt(Unknown Source) at Program.TriangularGrid(Program.java:42) at Program.main(Program.java:22) Removing close() isn't helping https://code.sololearn.com/cyx5782X6K5F/?ref=app
5 Respuestas
+ 2
I got it, you have to define the scan variable like a global variable.
public static Scanner scan = new Scanner(System.in);
public static void main(String[] args) {
....
}
For example:
http://stackoverflow.com/questions/12832006/scanner-error-with-nextint
+ 3
Hi Casey,
You need to send your inputs into separate lines to compile your code. Sololearn just compile your code according the inputs that you send it is not like IDE.
Take a look this code when just send one input.
https://code.sololearn.com/cVYEl0h520tj/#java
JIC: http://stackoverflow.com/questions/12832006/scanner-error-with-nextint
+ 1
Yes, I was thinking that too cause the code worked fine in Eclipse.
I want it to run in SoloLearn too.
I send my input in multiple lines, It doesn't work.
for example:
1
5
This gives the value of 'choice' as 1 which then calls the TriangularGrid() and then passes the value "5" in the variable 'value'.
What am I doing wrong?
+ 1
I also tried the if(hasNextInt()) statement but that just messes up all the variable declaration for some reason.
+ 1
Thank you so much :D
It worked.