+ 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"); } } } }

12th Apr 2017, 3:15 AM
Manjit Kumar
Manjit Kumar - avatar
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"); } }
12th Apr 2017, 11:29 AM
Babak
Babak - avatar
+ 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"); } } } }
12th Apr 2017, 3:27 AM
Edward
+ 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"); } }
12th Apr 2017, 3:37 AM
Babak
Babak - avatar
+ 4
oops sorry
12th Apr 2017, 4:18 AM
Edward
+ 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.
12th Apr 2017, 11:18 AM
Babak
Babak - avatar
+ 4
Your welcome
12th Apr 2017, 11:37 AM
Babak
Babak - avatar
+ 2
edward.. your answer doesnt give any output
12th Apr 2017, 4:11 AM
Manjit Kumar
Manjit Kumar - avatar
+ 2
i tried to.. add some codes... but i m new so, i failed
12th Apr 2017, 10:51 AM
Manjit Kumar
Manjit Kumar - avatar
+ 2
but when i enter age is 19 and money 200 then the output comes is welcome...
12th Apr 2017, 11:20 AM
Manjit Kumar
Manjit Kumar - avatar
+ 2
can you make this thing advance
12th Apr 2017, 11:20 AM
Manjit Kumar
Manjit Kumar - avatar
+ 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.
12th Apr 2017, 11:33 AM
Babak
Babak - avatar
+ 2
its preety good.. when i enter age more than 18 and money less than 500.. then the output is blank.. but its good
12th Apr 2017, 11:34 AM
Manjit Kumar
Manjit Kumar - avatar
+ 2
you are awesome
12th Apr 2017, 11:36 AM
Manjit Kumar
Manjit Kumar - avatar