This week's giveaway is in the Beginning Java forum.
We're giving away four copies of Bad Programming Practices 101 (e-book) and have Karl Beecher on-line!
See this thread for details.
Win a copy of Bad Programming Practices 101 (e-book) this week in the Beginning Java forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Array initialization  RSS feed

 
Ranch Hand
Posts: 61
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.
 
Enthuware Software Support
Rancher
Posts: 4185
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: 61
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
Rancher
Posts: 4185
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.
 
Bartender
Posts: 2174
46
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.
 
For my next feat, I will require a volunteer from the audience! Perhaps this tiny ad?
Why should you try IntelliJ IDEA ?
https://coderanch.com/wiki/696337/IntelliJ-IDEA
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!