Java Training in Chennai – Data Types, Variables and Operators Puzzles with Answers – Part – III

Java Training in Chennai – Data Types, Variables and Operators Puzzles with Answers – Part – III

Here in this blog we are discussing about Java Training in Chennai – Data Types, Variables and Operators Puzzles with Answers – Part – III . They are :

   We have already discussed about it in the previous blogs ” Java Training in Chennai – Data Types, Variables and Operators Puzzles with Answers – Part – I & II ”

_______________________________________________________________________________

 class SelectionStatements {

        public static void main(String args[])

        {

            int var1 = 5;

            int var2 = 6;

            if ((var2 = 1) == var1)

                System.out.print(var2);

            else

                System.out.print(++var2);

        }

    }

    class CommaLearningDemo {

        public static void main(String args[])

        {   

             int sum = 0;

             for (int i = 0, j = 0; i < 5 & j < 5; ++i, j = i + 1)

                 sum += i;

                     System.out.println(sum);

        }

    }

    class JumpStatments {

        public static void main(String args[])

        {       

             int x = 2;

             int y = 0;

             for ( ; y < 10; ++y) {

                 if (y % x == 0)

                     continue; 

                 else if (y == 8)

                      break;

                 else

                    System.out.print(y + ” “);

             }

        }

    }

class Output {

        public static void main(String args[])

        {   

           final int a=10,b=20;

          while(a<b)

          {

           System.out.println(“Hello”);

          }

          System.out.println(“World”);

         }

    }

    class Output {

        public static void main(String args[])

        {   

             int a = 5;

             int b = 10;

             first: {

                second: {

                   third: {

                       if (a ==  b >> 1)

                           break second;

                          }

                   System.out.println(a);

                }

                System.out.println(b);

             }

        }

    }

public class Example {

  public static void main(String[] args) {

    byte b = 3;

    b = -b;

    System.out.println(b);

  }

}

public class Example {

  public static void main(String[] args) {

    double d = 259;

    byte b = (byte)d;

    System.out.println(b);

  }

}

public class Example {

  public static void main(String[] args) {

    String s = “456”;

    int i = 123;

    System.out.println((int)i + s);

  }

}

public class Example {

  public static void main(String[] args) {

    String s = “123”;

    Object o = s;

    s = (String)o;

    System.out.println(s);

  }

}

public class Conversions

{

    public static void main(String args[])

    {

        byte x;

        int a = 270;

        double b = 128.128;

        x = (byte) a;

        System.out.println(“a and x ” + a + ” ” + x);

        a = (int) b;

        System.out.println(“b and a ” + b + ” ” + a);

        x = b;

        System.out.println(“b and x ” + b + ” ” + x);

    }

}

class IntegerConversion

{

    public static void main(String args[])

    {

        long l = 55;

        int i = 44;

        short s = 33;

        byte b    = 22;

        i = (int) l;

        s = (short) i;

        b = (byte) s;

        System.out.println(“l = ” + l);

        System.out.println(“i = ” + i);

        System.out.println(“s = ” + s);

        System.out.println(“b = ” + b);

    }

}

public class IAmGreat {

    public static void main(String args[]) {

        int i = 132;

        short s = 15;

        byte b = (byte) i;

        int x = b + s;

        System.out.println(“Value of x is ” + x);

    }

}

public class DemoOnbyte

{

    public static void main(String[] args)

    {

        byte a = -0x15;

        byte c = (a >> 4);

        System.out.print(c);

    }

}

public class DemoOnbyte

{

    public static void main(String[] args)

    {

        byte a = -0x15;

        byte c = (a >> 4);

        System.out.print(c);

    }

}

class IntegerGroupAddition

{

    public static void main(String args[])

    {

        long l = 30;

        int i = 50;

        short s = 60;

        byte b = 70;

        int sum = l + i + s + b;

        System.out.println(“Sum = ” + sum);

    }

}

class SumOfDoubles                            

{

    public static void main(String args[])

    {  

        double d1 = 0.7;

        double d2 = 77.0/1000.0;

        double d3 = d1 * 10;

        double d4 = 77E+2;

        double d5 = 77E-5;

        double sum = d1 + d2 + d3 + d4 + d5;

         System.out.println(“sum = ” + sum);

    }

}

 

public class Test{

                                public static void main(String[] args) {

                                int i = 5, j = 8, k = 0;

                                if(i > j && i++ < 10 && (k += i + j) > 10){

                                                System.out.print(“true”);

                                }

                                System.out.print(i);

                                System.out.print(j);

                                System.out.print(k);

                }

}

public class Test{

                public static void main(String[] args) {

                                int i = 1, j = 1, k = 1;

                                if( i++ > 1 && j++ < 2 || k++ == 1 )

                                                System.out.print(1);

                                else

                                                System.out.print(2);

                                System.out.print(i);

                                System.out.print(j);

                                System.out.print(k);

                }

}

public class Test{

                public static void main(String[] args) {

                                int i = 50, j = 10;

                                int k = i + 10 / j;

                                System.out.println(k);

                }

}

public class Test{

                public static void main(String[] args){                

                                int  i = 2;

                                System.out.println(~i);

                }                             

}

public class Test{

                public static void main(String[] args){                

                                int i = 2;

                                System.out.println(i << 3);

                }                             

}

public class Test{

                public static void main(String[] args){                

                                int i = 32;

                                System.out.println(i >> 3);

                }                             

}

public class Test{

                public static void main(String[] args){

                                int  i = -32;

                                System.out.println(i>>>3);

                }

}

public class Test{

                public static void main(String[] args){                

                                int  i = 10, j = 5;

                                System.out.println(i & j);

                }

}

public class Test{

                public static void main(String[] args){                

                                int i = 5, j = 2;

                                System.out.println(i | j);

                }

}

public class Test{

                public static void main(String[] args){                

                                int i = 5, j = 3;

                                System.out.println(i ^ j);

                }

}

class LeftShiftOperator {

        public static void main(String args[])

        {       

             byte x = 64;

             int i;

             byte y;

             i = x << 2;

             y = (byte) (x << 2)

             System.out.print(i + ” ” + y);

        }

    }

public class MyFor{

    public static void main(String argv[])

{

                    int i, j;

    outer:

                    for (i=1;i <3;i++)

                        inner:

                    for(j=1; j<3; j++)

{

                        if (j==2) continue outer;                        System.out.println(“Value for i=” + i + ” Value for j=” +j);

                    }

    }

}

_______________________________________________________________________________________

References:

https://payilagam.com/blogs/java-training-in-chennai-data-types-variables-and-operators-puzzles-with-answers/

      https://payilagam.com/blogs/java-training-in-chennai-data-types-variables-and-operators-puzzles-with-answers-part-ii/

COURTESY :

                               www.quizover.com, www.gocertify.comwww.geeksforgeeks.orgwww.developer.com

                               www.meritcampus.comwww.sanfoundry.com , www.javacodeexamples.comwww.jchq.net