Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

putting elements into array  RSS feed

 
comrade wank
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

i want to put elements in "arr[int...x]" at run time via "input.nextInt()"!! each time i run the for loop-give an input and store it in the static variable "int l[]" but how can i pass it into the argument of "arr[int...x]"!!! Please help me!!! please tell me if i have applied some wrong concept!!!
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
arr is a method - you put arguments to a method in parentheses ().
Square brackets [] are used to access arrays.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to CodeRanch comrade!

Hint: method call is ended with []

<edit>Joanne beaten me ;) </edit>
 
comrade wank
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks guys for your swift response but "arr[]" is only a writing mistake which i have commited here, even if i write it as "arr(l);" - when i run the program it takes the input and says:::

Enter the no. of inputs: 2
23
34
Exception in thread "main" java.lang.NullPointerException
at random3.Random3.main(Random3.java:17)
Java Result: 1
BUILD SUCCESSFUL (total time: 8 seconds)

It never diplays the desired result (i mean the for loop of arr(int...x) does nothing)!! please help me if there is any conceptual problem in this!!
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's because you haven't initialised your l variable.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!