Skip to content

Commit ea3efff

Browse files
authored
MP-22: added IfElse.java (#8)
1 parent ec85180 commit ea3efff

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package ru.mentee.power;
2+
3+
import java.util.Scanner;
4+
5+
public class IfElse {
6+
7+
public static void main(String[] args) {
8+
int age;
9+
boolean hasLicense;
10+
Scanner scanner = new Scanner(System.in);
11+
System.out.print("Enter your age:");
12+
age = scanner.nextInt();
13+
System.out.println("Do you have driver's license? yes/no");
14+
if (scanner.nextLine().equalsIgnoreCase("yes")) {
15+
hasLicense = true;
16+
} else {
17+
hasLicense = false;
18+
}
19+
if (age >= 18 && hasLicense){
20+
System.out.println("You can rent a car!");
21+
}else{
22+
System.out.println("Sorry, you can't rent a car.");
23+
}
24+
}
25+
26+
}

0 commit comments

Comments
 (0)