Does this app have a limit on how many user input your code can recieve? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Does this app have a limit on how many user input your code can recieve?

I am currently practicing with nested statements and my code tends to have errors with certain parts which I am sure to be syntax and logically sound.

20th Jun 2019, 3:23 PM
David Allen Dominden
David Allen Dominden - avatar
6 Answers
+ 4
There is no limit (that I know of), but because SL requires that all input is received at the beginning of the execution of your program, that may mess with inputs that are places within loops and such
20th Jun 2019, 3:44 PM
Faisal
Faisal - avatar
+ 2
Can you show us your code so we can explain to you?
20th Jun 2019, 3:50 PM
Gordon
Gordon - avatar
+ 2
One problem is that when taking input in int and next in String it reads pressing enter after number as String. You should add: sc.nextLine(); before taking next input. The other problem is when you want age as input and you press something else than number and program fails. You could add some verification by using hasNextInt() method.
20th Jun 2019, 8:59 PM
PBu
PBu - avatar
+ 1
Thank you guys so much for the help. Mostly to PBu, I didnt realize the difference between sc.next() and sc.nextLine()
21st Jun 2019, 12:02 AM
David Allen Dominden
David Allen Dominden - avatar
0
System.out.println("Enter your age here"); Scanner sc = new Scanner(System.in); String scanned = sc.next(); //Converts user input to integer int age = Integer.parseInt(scanned); if (age >= 18){ System.out.print("What is your favorite food?"); String food = sc.nextLine(); if (food.equals("pizza")){ System.out.println("Mine too!"); } else{ System.out.print("I like other foods"); } } else if (age >= 13){ System.out.println("You are a teenager"); } else{ System.out.println("You are a young child"); }
20th Jun 2019, 3:51 PM
David Allen Dominden
David Allen Dominden - avatar
0
you can rewrite that code this way, and it will works String food = sc.next(); next() reads string to next space or end of line (as default) nextLine() reads string to next end of line (as default)
21st Jun 2019, 12:15 AM
zemiak