Computer Applications
Give the output of the following program segment:
String a="10", b="20";
int x=Integer.parseInt(a);
int y=Integer.valueOf(b);
System.out.println(x+y);
System.out.println(a+b);
Java
Java Library Classes
12 Likes
Answer
30
1020
Working
Integer.parseInt and Integer.valueOf convert the strings a and b into their corresponding numeric integers. x + y adds 10 and 20 to give 30 as the output. a and b are strings so addition operator concatenates them and prints 1020.
Answered By
7 Likes
Related Questions
A student is trying to convert the string present in x to a numerical value, so that he can find the square root of the converted value. However the code has an error. Name the error (syntax / logical / runtime). Correct the code so that it compiles and runs correctly.
String x= "25"; int y=Double.parseDouble(x); double r=Math.sqrt(y); System.out.println(r);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);