if statements

If the condition is true, run the code inside

int test = 1;
if (test == 1) {
    System.out.println("test pass");
}
test pass

if-else statements

If the condition is true, run the code inside
If nt of the if statements are true, run the else statement.

int test = 0;
if (test == 1) {
    System.out.println("test pass");
}

else {
    System.out.println("test failed"); 
}
test failed

Bool

boolean t = true;
boolean f = false;


if (t) {
    System.out.println("1");
}

if (f) {
    System.out.println("2");
}

if (f && !t) {
    System.out.println("3");
}

if (t && !f) {
    System.out.println("4");
}

if (t || f) {
    System.out.println("5");
}

if (!t || !f) {
    System.out.println("6");
}

if ((t && !f) && (t || f)) {
    System.out.println("7");
}

if ((!t || (t && f)) || t ) {
    System.out.println("8");
}

if (!((f || !t) || (f && t))) {
    System.out.println("9");
}

if (!((f && !t) || (f || t))) {
    System.out.println("10");
}
1
4
5
6
7
8
9
int test1 = 3;
int test2 = 1;

if (test1 == 0) {
    int test2 = 10;
} 
else if (test1 == 3) {
    int test2 = 5;
    int test1 = 0;
    System.out.println("Nice");
} 
else {
    int test2 = 3;
}

if (test1 > test2) {
    System.out.println("Work");
  } 
else if (test1 < test2) {
    System.out.println("Job");
  } 
else {
    System.out.println("Code");
  }
Nice
Work
public class Test { 
    public static void main(String[] args) 
    { 
        String s1 = "HELLO"; 
        String s2 = "HELLO"; 
        String s3 =  new String("HELLO"); 
  
        System.out.println(s1 == s2); 
        System.out.println(s1 == s3); 
        System.out.println(s1.equals(s2)); 
        System.out.println(s1.equals(s3)); 
    } 
} 
Test.main(null);
true
false
true
true

Rock paper Scissors using if-elseif-else

See comments for futher details :D

public class RPS 
{
    
    public static final String ROCK = "ROCK";
    public static final String PAPER = "PAPER";
    public static final String SCISSORS = "SCISSORS";

    //Scanner class to detect what move user plays
    public static String getPlayerMove()
    {
        Scanner in = new Scanner(System.in);
        String input = in.next();
        String playermove = input.toUpperCase();
        System.out.println("Player move is: "+ playermove);*
        return playermove;
    }    


    //Computer mobve is randomly generated through random function 
    public static String getComputerMove()
    {
        String computermove;
        Random random = new Random();
        int input = random.nextInt(3)+1;
        if (input == 1)
            computermove = RPS.ROCK;
        else if(input == 2)
            computermove = RPS.PAPER;
        else
            computermove = RPS.SCISSORS;
            
        System.out.println("Computer move is: " + computermove);
        System.out.println();
        return computermove;    
    }
    


    public static void main(String args[]) 
    {
      System.out.println("Enter any t of the following inputs:  ");
      System.out.println("ROCK");
      System.out.println("PAPER");
      System.out.println("SCISSORS");
      System.out.println();
          
      String playerMove = getPlayerMove();
      String computerMove = getComputerMove(); 
 
      //Tie
      if (playerMove.equals(computerMove))
            System.out.println("Game is Tie !!");
        // Player = Rock, Computer = Paper     
      else if (playerMove.equals(RPS.ROCK) &&  computerMove.equals(RPS.PAPER))
            System.out.println("Computer Wins");  
        // Player = Rock, Computer = Scissors  
      else if (playerMove.equals(RPS.ROCK) &&  computerMove.equals(RPS.SCISSORS))
            System.out.println("Player Wins");  
        // Player = Paper, Computer = Scissors  
      else if (playerMove.equals(RPS.PAPER) &&  computerMove.equals(RPS.SCISSORS))
            System.out.println("Computer Wins"); 
        // Player = Paper, Computer = Rock  
      else if (playerMove.equals(RPS.PAPER) &&  computerMove.equals(RPS.ROCK))
            System.out.println("Player Wins"); 
        // Player = Scissors, Computer = Paper  
      else if (playerMove.equals(RPS.SCISSORS) &&  computerMove.equals(RPS.PAPER))
            System.out.println("Player Wins"); 
        // Player = Scissors, Computer = Rock  
      else if (playerMove.equals(RPS.SCISSORS) &&  computerMove.equals(RPS.ROCK))
            System.out.println("Computer Wins"); 
        // Player = Paper, Computer = Scissors  
      else if (playerMove.equals(RPS.PAPER))
            System.out.println(computerMove.equals(RPS.SCISSORS) ? "Computer Wins": "Player wins");     
        // if input isn't rock, paper, or scissors
      else
        System.out.println("There was an error, please try again");   
    }
    
}

RPS.main(null);
|           System.out.println("Player move is: "+ playermove);*
illegal start of expression

|           return playermove;
illegal start of expression

Switch Case

public class RPS 
{
    
    public static final String ROCK = "ROCK";
    public static final String PAPER = "PAPER";
    public static final String SCISSORS = "SCISSORS";


    //Scanner class to detect what move user plays
    public static String getPlayerMove()
    {
        Scanner in = new Scanner(System.in);
        String input = in.next();
        String playermove = input.toUpperCase();
        System.out.println("Player move is: "+ playermove);
        return playermove;
    }    
        
    public static void main(String args[]) 
    {
      System.out.println("Enter any t of the following inputs:  ");
      System.out.println("ROCK");
      System.out.println("PAPER");
      System.out.println("SCISSORS");
      System.out.println();
          
      String playerMove = getPlayerMove();
      String computerMove = getComputerMove(); 
 

        switch (playerMove) {
           
            case ROCK:
             // if user input ROCK
                if (playerMove.equals(computerMove))
                    System.out.println("Game is Tie !!");
                else if (playerMove.equals(RPS.ROCK) &&  computerMove.equals(RPS.PAPER))
                     System.out.println("Computer Wins");  
                else if (playerMove.equals(RPS.ROCK) &&  computerMove.equals(RPS.SCISSORS))
                      System.out.println("Player Wins"); 
                else
                      System.out.println("There was an error, please try again");   
                break;
            
            case PAPER:
            // if user input is Paper
                if (playerMove.equals(computerMove))
                     System.out.println("Game is Tie !!");   
                else if (playerMove.equals(RPS.PAPER) &&  computerMove.equals(RPS.SCISSORS))
                     System.out.println("Computer Wins"); 
                else if (playerMove.equals(RPS.PAPER) &&  computerMove.equals(RPS.ROCK))
                     System.out.println("Player Wins"); 
                else
                     System.out.println("There was an error, please try again");
                break;
    
            case SCISSORS:
            // if user input is scissors
                if (playerMove.equals(computerMove))
                    System.out.println("Game is Tie !!"); 
                else if (playerMove.equals(RPS.SCISSORS) &&  computerMove.equals(RPS.ROCK))
                    System.out.println("Computer Wins");  
                else if (playerMove.equals(RPS.SCISSORS) &&  computerMove.equals(RPS.PAPER))
                    System.out.println("Player Wins"); 
                else
                    System.out.println("There was an error, please try again");
                break;
        }

    }
    
    //Computer mobve is randomly generated through random function 
    public static String getComputerMove()
    {
        String computermove;
        Random random = new Random();
        int input = random.nextInt(3)+1;
        if (input == 1)
            computermove = RPS.ROCK;
        else if(input == 2)
            computermove = RPS.PAPER;
        else
            computermove = RPS.SCISSORS;
            
        System.out.println("Computer move is: " + computermove);
        System.out.println();
        return computermove;    
    }
    

}

RPS.main(null);
Enter any one of the following inputs:  
ROCK
PAPER
SCISSORS

Player move is: PAPER
Computer move is: ROCK

Player Wins

De Morgan's Law

In essence, Not (A and B) is the same as Not A or Not B
Remember that "!" denotes Not.

This

boolean test1 = true;
boolean test2 = true;

if (!(test1 && test2)){
    System.out.println("Test1 and Test2 are both false");
}
else{
    System.out.println("They are both true");
}
They are both true

is the same as this

boolean test1 = true;
boolean test2 = true;

if (!test1 || !test2){
    System.out.println("Test1 and Test2 are both false");
}
else{
    System.out.println("They are both true once again");
}
They are both true once again