digrach

Using If With Multiple Expressions

Mar 8th, 2014
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.92 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3.  
  4. public class UsingIfWithMultipleExpressions {
  5.  
  6.     public static void main(String[] args) {
  7.  
  8.         Scanner sc = new Scanner(System.in);
  9.         System.out.println("Please enter a number");
  10.         int num = sc.nextInt();
  11.  
  12.         // And.
  13.         if (num > 50 && num < 100) {
  14.             System.out.println("The number you entered was greater than 50 AND less than 100");
  15.         }
  16.  
  17.         // Or.
  18.         if (num > 50 || num < 100) {
  19.             System.out.println("The number you entered was greater than 50 OR less than 100");
  20.         }
  21.  
  22.         System.out.println("Please enter your name:");
  23.         String name = sc.next();
  24.  
  25.         // And.
  26.         if (name.length() > 5 && name.length() < 20) {
  27.             System.out.println("The length of your name is longer than 5 characters AND shorter than 20!");
  28.         }
  29.  
  30.         // Or.
  31.         if (name.length() > 5 || name.length() < 20) {
  32.             System.out.println("The length of your name is longer than 5 characters OR shorter than 20!");
  33.         }
  34.  
  35.     }
  36.  
  37.  
  38. }
Advertisement
Add Comment
Please, Sign In to add comment