Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class UsingIfWithMultipleExpressions {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- System.out.println("Please enter a number");
- int num = sc.nextInt();
- // And.
- if (num > 50 && num < 100) {
- System.out.println("The number you entered was greater than 50 AND less than 100");
- }
- // Or.
- if (num > 50 || num < 100) {
- System.out.println("The number you entered was greater than 50 OR less than 100");
- }
- System.out.println("Please enter your name:");
- String name = sc.next();
- // And.
- if (name.length() > 5 && name.length() < 20) {
- System.out.println("The length of your name is longer than 5 characters AND shorter than 20!");
- }
- // Or.
- if (name.length() > 5 || name.length() < 20) {
- System.out.println("The length of your name is longer than 5 characters OR shorter than 20!");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment