0

What is the output of this java code?? And plz explain it.

char[]x="197".toCharArray(); int nine=Integer.parseInt(" "+x[1]); System.out.print(" "+x[1]+nine);

7th Apr 2017, 10:22 AM
Munaf Mulani
Munaf Mulani - avatar
2 odpowiedzi
+ 5
99 First line:- create char array {1,9,7} 2 line :- integer variable nine = 9; 3 line :- x[1] is 9 ,so 8 will be printed. Since you used "" before x[1],thus means its a string,hence will concat to nine (9).
7th Apr 2017, 10:27 AM
Meharban Singh
Meharban Singh - avatar
+ 1
The first line initializes an array of characters containing 3 elements: '1', '9' and '7' The second line initializes the "nine" variable via parsing an integer number from a string formed by " " and the second element of the array (first is indexed with 0). Here replace " " with "", unless parsing won't understand " 9" as a number, but "9" is. The third line prints a space, the 2nd element of your array, and the parsed number. The output will be " 99", if you replaced what I mentioned :)
7th Apr 2017, 10:30 AM
Magyar Dávid
Magyar Dávid - avatar