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
8 odpowiedzi
+ 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
+ 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
+ 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;
+ 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
0
I think your input syntex is not correct
0
Please check my code.. i have shared
0
Please check my code this method is called each time when user input any number
0
Its a good advice I'll create another method .. and try again