Showing posts with label JAVA. Show all posts
Showing posts with label JAVA. Show all posts

Saturday, 28 November 2015

SwitchCase statement in Java

package day1.examples;

public class ExampleSwitchCase {

            public static void main(String[] args) {

                        int j = 2;

                        switch (j) {

                        case 0:
                                    System.out.println("Value is 0");
                                    break;
                                   
                        case 1:
                                    System.out.println("Value is 1");
                                    break;
                                   
                        case 2:
                                    System.out.println("Value is 2");
                                    break;
                                   
                        default :
                                    System.out.println("No Value");
                                    break;
                        }

            }

}





package day1.examples;

public class ExampleSwitchCase {

            public static void main(String[] args) {

                        String  j = "Two";

                        switch (j) {

                        case "Zero":
                                    System.out.println("Value is 0");
                                    break;
                                   
                        case "One":
                                    System.out.println("Value is 1");
                                    break;
                                   
                        case "Two":
                                    System.out.println("Value is 2");
                                    break;
                                   
                        default :
                                    System.out.println("No Value");
                                    break;
                        }

            }

}


And Or in Java

package day1.examples;

public class ExampleAndOr {

            public static void main(String[] args) {

                        int x, y;
                        x = 10;
                        y = -10;
                        // && And
                        // || Or

                        if (x > 0 && y > 0) {

                                    System.out.println("Both Numbers are Positive");
                        } else if (x > 0 || y > 0) {

                                    System.out.println("Atleast One number is Positive");

                                    System.out.println("          -- By Lokanadham Thandlam");
                        }

            }

}




Do While Loop in Java

package day1.examples;

public class ExampleDoWhile {

            public static void main(String[] args) {
                        System.out.println("Hello Lokanadham Thandlam");

                        int x = 10;

                        do {
                                    System.out.println("x = " + x);
                                    x--;

                        } while (x > 0);
            }

}



While Loop in Java

package day1.examples;

public class ExampleWhile {

            public static void main(String[] args) {
                        System.out.println("Hello Lokanadham Thandlam");

                        int x = -10;

                        while (x <= 0) {
                                    System.out.println("X Value is " + x);

                                    // you can write any one of incremental value here
                                    // x = x +1;
                                    // x += 1;
                                    x++;

                        }

            }

}


For Loop in Java Language

package day1.examples;

public class ExampleFor {

            public static void main(String[] args) {
                        // for (initial value; condition; increment/decrement)

                        System.out.println("Hello Lokanadham Thandlam");

                        for (int i = 0; i <= 10; i++) {
                                    System.out.println("i = " + i);
                        }
            }

}





If Statement in Java Language

package day1.examples;

public class ExampleIf {

            public static void main(String[] args) {

                        System.out.println("Hello Lokanadham Thandlam");

                        int x = 20;
                        int y = 40;

                        if (x == y) {
                                    System.out.println(" X is equal to Y");
                        } else if (x > y) {
                                    System.out.println("X is Greater to Y");
                        }

                        else if (x < y) {
                                    System.out.println("X is Less than Y");

                        }

            }

}