package branching;

public class IfThenElse {

     public static void main(String[] args) {

        int i = 10;

        if (i > 5) {

            System.out.println("This will print");

        }

        if (i < 10) {

            System.out.println("This will not print");

        }

    }

}

 

 

 

 

public static void main(String[] args) {

    int i = 10;

    if (i > 5)

        System.out.println("This will print");

    if (i < 10)

        System.out.println("This will not print");         

}

 

 

 

 

public static void main(String[] args) {

    int i = 10;

    if (i > 10) {

        System.out.println("The number is greater than 10");

    } else {

        System.out.println("The number is NOT greater than 10");

    }

}

 

 

 

 

public static void main(String[] args) {

    int i = -10;

    if (i >= 0 && i % 2 == 0) {

        System.out.println("Positive even number");

    } else if (i >= 0) {

        System.out.println("Odd even number");

    } else if (i < 0 && i % 2 == 0) {

        System.out.println("Negative even number");

    } else {

        System.out.println("Negative odd number");

    }

}

 

 

 

 

public static void main(String[] args) {

    int i = -10;

    if ( i % 2 == 0) {

        if (i >= 0) {

            System.out.println("Positive even number");

        } else {

            System.out.println("Negative even number");

        }

    } else {

        if (i >= 0) {

            System.out.println("Positive odd number");

        } else {

            System.out.println("Negative odd number");

        }

    }

}    

 

 

 

 

public static void main(String[] args) {

    int i = 2;

    switch (i) {

        case 1 :

            System.out.println("The number is 1");

            break;

        case 2 :

             System.out.println("The number is 2");

             break;

        case 3 :

            System.out.println("The number is 3");

            break;

        default :

            System.out.println("The number is greater than 3");

            break;

        }

    }

}

 

 

 

 

switch (i) {

    case 1 :

        System.out.println("The number is 1");

    case 2 :

        System.out.println("The number is 2");                   

    case 3 :

        System.out.println("The number is 3");

    default :

        System.out.println("The number is greater than 3");

}

 

 

 

 

switch (i) {

    case 1 :

    case 2 :

    case 3 :

        System.out.println("The number is 1, 2 or 3");

        break;

    default :

        System.out.println("The number is greater than 3");

        break;

}

 

 

 

 

public static void main(String[] args) {

    String s = "one";

        switch (s) {

            case "zero" :

                System.out.println("The number is 0");

                break;

             case "one" :

                 System.out.println("The number is 1");

                 break;

             case "two" :

                 System.out.println("The number is 2");

                 break;

             default :

                 System.out.println("The number is greater than 2");

                 break;

        }

    }

}

 

 

 

 

public static void main(String[] args) {

    int i = 22;

    String s = i % 2 == 0 ? "even" : "odd";

    System.out.println("The number is "+s);

}

 

 

 

 

public static void main(String[] args) {

    for (int i = 0; i < 10; i++) {

        System.out.println("The number is "+i);

    }

}

 

 

 

 

public static void main(String[] args) {

    for (int i = 0; i < 10; i++) {

        int squared = i * i;

        System.out.println("The number is "+i);

        System.out.println("Squared is "+squared);

    }

}

 

 

 

 

public static void main(String[] args) {

    String s = "Welcome to Java";

    for (int i = s.length(); i > 0; i--) {

        System.out.print(s.charAt(i-1));

    }

}

 

 

 

 

public static void main(String[] args) {

    int[][] numbers = {{1,2,3},{4,5,6},{7,8,9},{10,11,12}};

    int result = 0;

    for (int i = 0; i < numbers.length; i++) {

        for (int j = 0; j < 3; j++) {

            result += numbers[i][j];

        }

    }

    System.out.println(result);

}

 

 

 

 

public static void main(String[] args) {

    int[] numbers = {3,5,43,2,5,33,2,45,5,3};

    int checkGreaterThan = 100;

    int sumOfNumbers = 0;

    for (int i = 0; i < numbers.length; i++) {

        sumOfNumbers += numbers[i];

    }

    if (sumOfNumbers > checkGreaterThan) {

        System.out.println("It is greater");

    }      

}

 

 

 

 

for (int i = 0; i < numbers.length; i++) {

    sumOfNumbers += numbers[i];

    if (sumOfNumbers > checkGreaterThan) {

        System.out.println("It is greater");

        break;

    }

}

 

 

 

 

public static void main(String[] args) {

    int[][] numbers = {{11,12,3},{14,15,16},{17,18,19},{10,11,12}};

    int checkGreaterThan = 100;

    int sumOfNumbers = 0;

    outer: for (int i = 0; i < numbers.length; i++) {

        for (int j = 0; j < 3; j++) {

            sumOfNumbers += numbers[i][j];

            if (sumOfNumbers > checkGreaterThan) {

                System.out.println("It is greater");

                break outer;

            }

        }

    }                  

}

 

 

 

 

public static void main(String[] args) {

    int[] numbers = {3,5,44,2,5,33,2,45,5,3,44,22,26,7,9,11};

    int checkGreaterThan = 100;

    int sumOfNumbers = 0;

    for (int i = 0; i < numbers.length; i++) {

        if (numbers[i] % 2 != 0) {

            continue;

        }

        sumOfNumbers += numbers[i];

        if (sumOfNumbers > checkGreaterThan) {

            System.out.println("It is greater");

            break;

        }

    }                  

}

 

 

 

 

public static void main(String[] args) {

    int i = 0;

    while (i < 10) {

        System.out.println("The number is "+i);

        i++;

    }

}

 

 

 

 

public static void main(String[] args) {

    int i = 0;

    do {

        System.out.println("The number is "+i);

        i++;

    } while (i < 10);

}