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);
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).
+ 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 :)