Sunday, September 8, 2013

Java Logic Questions Part - V

Posted by Sharath Chandra
Hi Friends, 

I am back with some of the simplest yet logic questions - gathered from many of the java books. If you want just ask me that book name! at [email protected] 



Question 9:

public class Test2 {

public static void main(String[] args) {

System.out.println(12654+4562l);

}

}


Question 10: 

public class Test3 {

public static void main(String[] args) {

        char a = 'A';
        int i = 10;
        System.out.print( true  ? a : i);
        System.out.print( false ? i : 'B');
        System.out.print( false ? a : 'B');

        }
}

Result? TRY TO COMPILE IN YOUR BRAIN INSTEAD OF DOING IT IN IDE! 

|
|
|
|
|
|
|
|

|
|
|
|
|
|
|
|

|
|
|
|
|
|
|
|

|
|
|
|
|
|
|
|

|
|
|
|
|
|
|
|

Question 9: 
Answer
It will print 

17216

Because if you closely observe the 4562l - Last one seems like 1 but it is 'l' small L so - it will treat it as 4562 and adds to 12654 as simple addition. 


Question 10: 
Answer
It will print 

6566B
- It is best practice to use the same type for the second and third operands in condition expressions - else it will print the ASCII Values of next operand. 



Please Share - Because in Knowledge 
Sharing is Gaining!


For Previous Parts of Java Logic Questions