Detailed Print – Computer Sir Ki Class

Login


Lost your password?

Don't have an account ?
Register (It's FREE) ×
  


Shop
siteicon
Solved Problem#JAVA#7246

Problem Statement - Output Writing – Using integer wrapper

Give the output of the following code:

String A =”26″, B=”100″;
String D=A+B+”200″;
int x= Integer.parseInt(A);
int y = Integer.parseInt(B);
int d = x+y;
System.out.println(“Result 1 = “+D);
System.out.println(“Result 2 = ” +d);

Solution

		 

Click to open popup

Run Output

Result 1 = 26100200
Result 2 = 126

Solved Problem Understanding

String A= “26”, B= “100”; //numbers being initialised in string form
String D=A+B+ “200”;
D = “26” + “100” + “200” = “26100200”   //being the concatenation of strings
int x= Integer.parseInt(A);
x will contain 26 as number.
int y=Integer.parseInt(B);
y will contain 100 as number
int d=x+y;
d would be  26 + 100 = 126
System.out.println(“Result 1=” +D);
D would be 26100200
System.out.println(“Result 2 = ” +d);
d would be 126

Ans.
Result 1=26100200
Result 2=126