0

How to take input from user from any method out of main method(). In sololearn android app and web app.

I am trying to take input from user out of main(). It shows error "Exception in thread 'main' java. util. NoSuchElementException". Is their any way to take input in sololearn app. Please comment here.. https://code.sololearn.com/c3a25a15a4A2/?ref=app

2nd Aug 2021, 6:19 PM
Balram Singh
Balram Singh - avatar
8 Antworten
+ 1
your code is correct actually you have to give all input's as same time not after compilation that's why try to give all input at same time or try in eclipse or any online Compiler online gbd and select java language
2nd Aug 2021, 6:25 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 1
Thanks for your suggestion. But in this code I am trying to solve a query with "Zero Error" thats why i need next input. After user input wrong numbers
2nd Aug 2021, 6:28 PM
Balram Singh
Balram Singh - avatar
+ 1
This happening because you have created this method but you not using anywhere i mean u not calling thia method public static int validation(int n,String sub,Scanner sc){ //Scanner sc = new Scanner(System.in); if(n>100){ System.out.println("You can't have 100+ marks in "+ sub +"\n"); System.out.println("please enter again marks of "+ sub); n = sc.nextInt(); return n;
2nd Aug 2021, 6:32 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 1
Balram Singh this is static method i know u dont need to create object to call this validation method . Its not a constructor but where u calling this method and tell me one thing after this line please enter again marks why u taking this input it have no sense to return if u want to re-enter marks again then make one more method and put your all code which have written in top after validation method call it after first method it will ask for input again
2nd Aug 2021, 6:44 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
0
I think your input syntex is not correct
2nd Aug 2021, 6:22 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
0
Please check my code.. i have shared
2nd Aug 2021, 6:23 PM
Balram Singh
Balram Singh - avatar
0
Please check my code this method is called each time when user input any number
2nd Aug 2021, 6:39 PM
Balram Singh
Balram Singh - avatar
0
Its a good advice I'll create another method .. and try again
2nd Aug 2021, 7:00 PM
Balram Singh
Balram Singh - avatar