This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Hands On Software Engineering with Python and have Brian Allbey on-line!
See this thread for details.
Win a copy of Hands On Software Engineering with Python this week in the Jython/Python forum!
  • 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
Bartenders:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

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
Posts: 4259
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
Posts: 4259
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: 2203
47
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.
 
A teeny tiny vulgar attempt to get you to buy our stuff
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!