0
Would this code work?
5 odpowiedzi
+ 2
No it won't.
nextInt is a function, so you call it like this
nextInt();
+ 8
it should be nextInt()
+ 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");
}
}
}
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");
}
}
}
0
thank you both!