Win a copy of Grokking Bitcoin this week in the Cloud/Virtualization 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
  • Liutauras Vilda
  • Bear Bibeault
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Frits Walraven
Bartenders:
  • Carey Brown
  • salvin francis
  • Claude Moore

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: 4304
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: 4304
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: 2217
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.
 
I have always wanted to have a neighbor just like you - Fred Rogers. Tiny ad:
Create Edit Print & Convert PDF Using Free API with Java
https://coderanch.com/wiki/703735/Create-Convert-PDF-Free-Spire
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!