• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

generate random number into 2d arrays

 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator



i tried to put arr[i][b] = random.nextInt();
or arr[i][b] = random.nextInt(10);
and even arr[i][b] = ranNum
but it just wont work. please
 
Bartender
Posts: 1558
5
Eclipse IDE Java Linux
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Sara Brown,

Please CarefullyChooseOneForum. This issue does not seem to be related to Threads and Synchronization.

Further, please TellTheDetails. That is, instead of simply saying 'it just wont work', please mention what is the problem - compile time error, runtime exception, or something else?

Now, coming to your problem:

Firstly, there are no 2D arrays in Java. There are arrays, and arrays of arrays, and arrays of arrays of arrays and so on.

So, what you are doing is - declaring an array of length 2. That will contain array of length 3 each. That will contain objects of class Arrays.

Now, why do you need Arrays object? It is used to perform operations on arrays (like binary search, sort, comparison etc.). You are not doing any of them. Further, all the Arrays specific methods are static, so it doesn't make any sense to create object of Arrays. But since we don't need Arrays itself, we'll not get into that.

Secondly, you are simply generating a random number and that's it. You are not assigning it to anything. One statements of your trial ones is correct (arr[i][b] = random.nextInt();). But to make it work, arr must be of type int instead of Arrays (just think about it - you cannot assign int to Arrays).

I hope this helps.
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Moved to the Java in General forum.

Henry
 
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I hope you are not trying to put objects of the Arrays class into your array; you can’t instantiate Arrays.
reply
    Bookmark Topic Watch Topic
  • New Topic