if else program in java

If else conditional statement objective type questions in java




(1)

public class ControlStatement {
    public static void main(String[] args) {
         int a=25;
        
         if(~a>25)
             a++;
             a+=a;
            
         System.out.print(a);
    }
}      

What will be the output of above java program?

(a)-52
(b)50
(c)52
(d)Compiler error






Answer: (b)

(2)

public class ControlStatement {
    public static void main(String[] args) {
         int a=25;
        
         if(~a>25)
             a++;a+=a;
         else
             --a;

         System.out.print(a);
    }
}

What will be the output of above java program?

(a) 24
(b)-27
(c)-25
(d)Compiler error






Answer: (d)

(3)

public class ControlStatement {
    public static void main(String[] args) {
         int a=25;

         if(a-->a--){
             {
                 a='0';

             }
         }
         else
             --a;

         System.out.print(a);
    }
}

What will be the output of above java program?

(a) 22
(b) 24
(c) 48
(d)Compiler error






Answer: (c)

(4)

public class ControlStatement {
    public static void main(String[] args) {
         int a=25;

         if(a++>a--){
             a+=2;
         }
         else{
             break;
         }

         System.out.print(a);
    }
}

What will be the output of above java program?

(a) 25
(b) 26
(c) 27
(d)Compiler error






Answer: (d)

(5)

public class ControlStatement {
    public static void main(String[] args) {
         int a=25;

         if(a>10)
             System.out.print("ok");
         else if(a>10)
             System.out.print("bye");
    }
}

What will be the output of above java program?

(a) ok

(b) bye

(c) okbye

(d)Compiler error






Answer: (a)

(6)

public class ControlStatement {
    public static void main(String[] args) {
         int a=25;
         if(a>10)
             System.out.print("ok");
         else if(true)
             System.out.print("bye");
    }
}

What will be the output of above java program?

(a) ok
(b) bye
(c) okbye
(d)Compiler error





1 comment:

Unknown said...

Answer for 6) is a)