Monday, September 9, 2013

Java Logic Questions Part - VI

Posted by Sharath Chandra
Question 11: 

public class Test4 {

public static void main(String[] args) {

        System.out.print("I "+"LOVE ");
        System.out.print('Y'+'O'+'U');
        }




Question 12: 

public class Test5 {

public static void main(String[] args) {
        
        System.out.println("a\u0022.length() + \u0022b".length()); 
        // \u0022 means " 
   
        } 



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

|
|
|
|
|
|
|
|

|
|
|
|
|
|
|
|

|
|
|
|
|
|
|
|

|
|
|
|
|
|
|
|

|
|
|
|
|
|
|
|

Question 11: 
Answer
It will print 

I LOVE 253
So where is YOU - It will add all the ASCII values of Y O U and prints 253 since we used '' inside SOP statement. 

Question 12: 
Answer
It will print 

2

that means System.out.println("a".length() + "b".length()); 1+1 = 2 
So - Java Provides no special treatment for Unicode escapes within the string literals. 







Please Share - Because in Knowledge 
Sharing is Gaining!


For Previous Parts of Java Logic Questions