- 1

What happen?

if we remove the 4th line of the program where 42 is written then also output will be 4 than what is the difference inserting the line and not? and what that line indicates. kindly help.

10th Jan 2017, 12:45 PM
Jitu Barman
Jitu Barman - avatar
6 Answers
+ 2
What's the program?
10th Jan 2017, 1:08 PM
Igor B
Igor B - avatar
+ 2
The last line print the value of 'x' which was initialized in previous line with the value of element indiced [1][0] in the 'myArr' array... The line you attempt to remove ( myArr[0][2]=42; ) assign a new value to element indiced [0][2] in 'myArr': this line of code don't change the value assigned to 'x' so it's ever output '4' ;)
10th Jan 2017, 1:30 PM
visph
visph - avatar
+ 2
It isn't required for this output, but what's the context? While we dont know it ( maybe you do, but you've posted only an extract or example without context ), we only can guess that line have arbitrary utility and by default, we must consider it's required for something ^^
10th Jan 2017, 6:18 PM
visph
visph - avatar
0
public class Program { public static void main(String[] args) { int[ ][ ] myArr = { {1, 2, 3}, {4}, {5, 6, 7} }; myArr[0][2] = 42; int x = myArr[1][0]; System.out.println(x); } }
10th Jan 2017, 1:14 PM
Jitu Barman
Jitu Barman - avatar
0
I need to understand the basic of Java, JavaScript and PHP. I want to apply for a job overseas in Russia. and the job requires a candidate with engineering degree in computer science. but I am an engineer with electronics and communication engineering. that's why it's been a little difficult for me to understand. I really really need that job. I would be glad if you can help me understand, if u don't mind. thank you.
10th Jan 2017, 1:18 PM
Jitu Barman
Jitu Barman - avatar
0
why it is required? without that the output will be same.
10th Jan 2017, 1:31 PM
Jitu Barman
Jitu Barman - avatar