Advertisement
Kancho

Age_Nested_Ifs_Solution

Jan 27th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Address {
  4. public static void main (String [] args){
  5. Scanner keyboard = new Scanner(System.in);
  6. System.out.print("Enter male or female: ");
  7. String gender = keyboard.next();
  8. System.out.print("Enter your age: ");
  9. int age = keyboard.nextInt();
  10. if (gender.equals("female")) {
  11. if (16 <= age && age < 22){
  12. System.out.printf("You are a girl over 16 years old. You can enter the party%nbut you are not allowed to booze!");
  13. }else if (16 > age ) {
  14. System.out.println("You are a girl under 16 years old. You cannot enter the party!");
  15. }else {
  16. System.out.printf("You are a woman over 22 years old. You are welcomed in the party%nand you are allowed to booze! ");
  17. }
  18. }else if (gender.equals("male")){
  19. if(16 <= age && age < 22 ){
  20. System.out.printf("You are a man over 16 but less than 22 years old. You can enter the party%nbut you are not allowed to booze! ");
  21. }else if (16 > age){
  22. System.out.println("You are a boy under 16 years old. You cannot enter the party!");
  23. }else {
  24. System.out.printf("You ara a man over 22 years old. You ara welcomed the party%nand You are allowed to booze!");
  25. }
  26. }
  27.  
  28. }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement