• Post Reply Bookmark Topic Watch Topic
  • New Topic

Arrays -Getting all 0's in out put?  RSS feed

 
Slaxmi Raj
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this program will print all 0's . would you please tell me why?

output:0000000000.
 
James Boswell
Bartender
Posts: 1051
5
Chrome Eclipse IDE Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What did you expect to be output? Read up on default values for primitives to discover the reason.

See here: http://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html
 
Slaxmi Raj
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would like to display 1 2 3 4 5 6 7 8 9 10 in output.
please tell me what is code for this by using arrays.
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Slaxmi Raj wrote:I would like to display 1 2 3 4 5 6 7 8 9 10 in output.
please tell me what is code for this by using arrays.


Well, basically, if you want those values in the array, you need to actually put those values in the array. There is no trick here -- just do it.

Henry
 
Campbell Ritchie
Marshal
Posts: 56562
172
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry Wong wrote:. . . you need to actually put those values in the array. . . .
. . . like here.
 
Sccot Smith
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
because default value of int variable is 0!
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sccot Smith wrote:because default value of int variable is 0!


Only for member variables, not locals.

And in any case, he doesn't have an int variable. He has an int[] variable, and, as it turns out, the default value for int array elements is also 0.
 
Sccot Smith
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeff Verdegan wrote:
Sccot Smith wrote:because default value of int variable is 0!


Only for member variables, not locals.

And in any case, he doesn't have an int variable. He has an int[] variable, and, as it turns out, the default value for int array elements is also 0.

Sorry!l don't have a clear explanation!
Not int variable but int array element!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!