0

Would this code work?

29th Nov 2017, 2:05 PM
Jerald Loh
5 ответов
+ 2
No it won't. nextInt is a function, so you call it like this nextInt();
29th Nov 2017, 2:09 PM
Jonas Schröter
Jonas Schröter - avatar
+ 8
it should be nextInt()
29th Nov 2017, 2:09 PM
Shamima Yasmin
Shamima Yasmin - avatar
+ 2
https://www.sololearn.com/Codes/ ^You can test code here and see if it works. As for your code, You'll want to put () on the end of nextInt, so it'll be nextInt(). Also, I changed your variable, named variable, to scnr instead. Take some time to research common practices, naming conventions, and just the typical standards for formatting your code. Trust me, that's a habit you'd rather form right now as a good one, rather than having a bad habit you're trying to break later. Save yourself time now by learning it properly. https://code.sololearn.com/cGj32je8aGB0/#java import java.util.Scanner; class MyClass { public static void main(String[ ] args) { Scanner scnr = new Scanner(System.in); int age; System.out.println("what is your age?"); age = scnr.nextInt(); if(age > 16){ System.out.println("welcome"); } else { System.out.println(" too young"); } } }
29th Nov 2017, 2:13 PM
AgentSmith
0
import java.util.Scanner; class MyClass { public static void main(String[ ] args) { Scanner variable = new Scanner(System.in); int age; System.out.println("what is your age?"); age= variable.nextInt; if(age>16) {System.out.println("welcome");} else {System.out.println(" too young"); } } }
29th Nov 2017, 2:05 PM
Jerald Loh
0
thank you both!
29th Nov 2017, 2:13 PM
Jerald Loh