Computer Applications
Give the output of the following code:
String P = "20", Q ="19";
int a = Integer.parseInt(P);
int b = Integer.valueOf(Q);
System.out.println(a+""+b);
Answer
Output of the above code is:
2019
Working
Both Integer.parseInt() and Integer.valueOf() methods convert a string into integer. Integer.parseInt() returns an int value that gets assigned to a. Integer.valueOf() returns an Integer object (i.e. the wrapper class of int). Due to auto-boxing, Integer object is converted to int and gets assigned to b. So a becomes 20 and b becomes 19. 2019 is printed as the output.
Related Questions
Predict the output of the following code snippet:
char ch='B', char chr=Character.toLowerCase(ch); int n=(int)chr-10; System.out.println((char)n+"\t"+chr);String s1 = "45.50"; String s2 = "54.50"; double d1=Double.parseDouble(s1); double d2=Double.parseDouble(s2); int x= (int)(d1+d2);What is value of x?
The method to convert a lowercase character to uppercase is:
- String.toUpperCase( )
- Character.isUppercase( char )
- Character.toUpperCase( char )
- toUpperCase ( )