+ 4
Can anyone add the user input in this code
add user input for both age and money. you are free to add the lines.. or modify whole code. i just want user input for both. age and money public class Program { public static void main(String[] args) { int age = 22; int money = 800; if (age > 18) { if (money > 500) { System.out.println("get out"); }else { System.out.println ("welcome"); } } } }
13 odpowiedzi
+ 4
import java.util.Scanner;
public class Program
{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int age = 0;
int money = 0;
System.out.print("What is your age? ");
age = input.nextInt();
System.out.print("\nHow much money do you have? ");
money = input.nextInt();
if (age < 18)
{
System.out.println("\nGet out!");
}
else if (money > 500)
System.out.println("\nWelcome");
}
}
+ 4
import java.util.Scanner;
public class Program {
public static void main(String[] args) {
Scanner input = new Scanner ();
int age = input.nextInt ();
int money = 800;
if (age > 18) {
if (money > 500) {
System.out.println("get out");
}else {
System.out.println ("welcome");
}
}
}
}
+ 4
import java.util.Scanner;
public class Program
{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int age = 0;
int money = 0;
System.out.print("What is your age? ");
age = input.nextInt();
System.out.print("\nHow much money do you have? ");
money = input.nextInt();
if (age < 18 && money < 500)
{
System.out.println("\nGet out!");
}
else
System.out.println("\nWelcome");
}
}
+ 4
oops sorry
+ 4
Don't worry, programming is all about try and error and in most of the case you'll learn from your failures. So keep going and be persist.
+ 4
Your welcome
+ 2
edward.. your answer doesnt give any output
+ 2
i tried to.. add some codes... but i m new so, i failed
+ 2
but when i enter age is 19 and money 200 then the output comes is welcome...
+ 2
can you make this thing advance
+ 2
You will kick out, even if you have more than 500 box in your pocket.
then basically there's no need for assessing money in the first place. But if you're an adult then the guy take a look at your pocket in order to tell you welcom.
+ 2
its preety good.. when i enter age more than 18 and money less than 500.. then the output is blank.. but its good
+ 2
you are awesome