Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

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: 4204
35
  • 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: 4204
35
  • 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: 2180
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!