digrach

Using If

Mar 8th, 2014
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.73 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3.  
  4. public class UsingIf {
  5.  
  6.     public static void main(String[] args) {
  7.  
  8.         int player1Health = 200;
  9.         int player2Health = 300;
  10.  
  11.  
  12.         if (player1Health == player2Health) {
  13.             System.out.println("Draw");
  14.         }
  15.  
  16.         if (player1Health < player2Health) {
  17.             System.out.println("Winner is player 2");
  18.         }
  19.  
  20.         if (player1Health > player2Health) {
  21.             System.out.println("Winner is player 1");
  22.         }
  23.  
  24.  
  25.         Scanner sc = new Scanner(System.in);
  26.         System.out.println("Please enter a number");
  27.         int num = sc.nextInt();
  28.  
  29.         // Less than.
  30.         if (num < 100) {
  31.             System.out.println("The number you entered was less than 100");
  32.         }
  33.  
  34.         // Greater than.
  35.         if (num > 100) {
  36.             System.out.println("The number you entered was greater than 100");
  37.         }
  38.  
  39.         // Greater than or equal to.
  40.         if (num >= 50) {
  41.             System.out.println("The number you entered was greater than or equal to 50");
  42.         }
  43.  
  44.         // Less than or equal to.
  45.         if (num <= 50) {
  46.             System.out.println("The number you entered was less than or equal to 50");
  47.         }
  48.  
  49.         // equals.
  50.         if (num == 10) {
  51.             System.out.println("The number you entered was equal to 10");
  52.         }
  53.  
  54.         // Not equal to.
  55.         if (num != 15) {
  56.             System.out.println("The number you entered was not equal to 15");
  57.         }
  58.  
  59.         System.out.println("Please enter your name:");
  60.         String name = sc.next();
  61.  
  62.         // equals.
  63.         if (name.length() == 10) {
  64.             System.out.println("The length of your name is equal to 10 characters!");
  65.         }
  66.  
  67.         // greater than.
  68.         if (name.length() > 5) {
  69.             System.out.println("The length of your name is longer than 5 characters!");
  70.         }
  71.  
  72.         // Not equal to.
  73.         if (name.length() != 25) {
  74.             System.out.println("The length of your name is not equal to 25 characters!");
  75.         }
  76.  
  77.  
  78.     }
  79.  
  80. }
Advertisement
Add Comment
Please, Sign In to add comment