• Post Reply Bookmark Topic Watch Topic
  • New Topic

Array initialization  RSS feed

 
Kelvin Okornoe
Ranch Hand
Posts: 48
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This code produces no output, but it is declared as an int and has been initialized, sort of. I expected this code to  something since it has been initialized if not a zero.


But this produces an output of zeros.
This code is from whizlabs test questions


And what is the difference between the two code snippet.
Your thoughts are welcomed.
 
Paul Anilprem
Enthuware Software Support
Ranch Hand
Posts: 4106
34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might want to try printing the length of the arrays using System.out.println(ints.length); and observe the output in both the cases.
 
Kelvin Okornoe
Ranch Hand
Posts: 48
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With the first code the length prints nothing.
The second code prints length of 3;
 
Paul Anilprem
Enthuware Software Support
Ranch Hand
Posts: 4106
34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kelvin Okornoe wrote:With the first code the length prints nothing.
The second code prints length of 3;

It can't print nothing. It must print a number.
 
Paweł Baczyński
Bartender
Posts: 2062
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Anilprem wrote:It can't print nothing. It must print a number.

I guess Kelvin put System.out.print(ints.length) inside the for loop...

Kelvin, if that is the case, put the print statement above of the loop.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!