0
What lines to add to script to have user input for the int age = userinput?
for example for this code to set the age to my desired number using userinput public class Program { public static void main(String[] args) { int age = 25; if(age <= 0) { System.out.println("Error"); } else if(age <= 16) { System.out.println("Too Young"); } else if(age < 100) { System.out.println("Welcome!"); } else { System.out.println("Really?"); } } }
5 Respuestas
+ 19
It happens! don't worry...
Now it works...enjoy ^_^
+ 17
@virginijus
It works! Try running it in the code playground...
we have to import the Scanner class to get input from the user and then we create an object called "input" for our class. This object specifies the type of input as :
input.nextInt();
Hope you got it :)
+ 16
import java.util.*;
// or import Java.util.Scanner;
public class Program {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int age = input.nextInt();
if(age <= 0) {
System.out.println("Error");
} else if(age <= 16) {
System.out.println("Too Young");
} else if(age < 100) {
System.out.println("Welcome!");
} else {
System.out.println("Really?");
}
}
}
+ 1
thx buddy,but i dont get it 😀,ive wrote same code as yours but it didnt worked for me
+ 1
thanx again