+ 2

How get output hi?

public class Program { public static void main(String[] args) { int age = 16; int money = 400; if (age > 18) { if (money > 500) { System.out.println("Welcome!"); } else { System.out.println("hi"); } } } }

12th Mar 2019, 1:46 AM
Priyanka Gotugade.
Priyanka Gotugade. - avatar
3 Respuestas
+ 6
Well we have 2 conditions here:- ✅ Is age > 18? ✅ Is money > 500? In order to get "hi" as the output, we need to ensure the 1st condition is true while the 2nd condition is false. Therefore, one of the desired input would be:- age = 19 (minimum) money = 500 (maximum)
12th Mar 2019, 6:19 AM
Zephyr Koo
Zephyr Koo - avatar
+ 2
int age = 20;
12th Mar 2019, 2:20 AM
Diego
Diego - avatar
+ 2
Zephyr Koo If money == 501 then the output is "Welcome!". You said it yourself: the condition money>500 needs to be false. EDIT: Nevermind.
12th Mar 2019, 6:22 AM
Diego
Diego - avatar