It's not a secret anymore!*
The moose likes Beginning Java and the fly likes Fill an array in a switch statement Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Fill an array in a switch statement" Watch "Fill an array in a switch statement" New topic
Author

Fill an array in a switch statement

Terence Doyle
Ranch Hand

Joined: May 30, 2001
Posts: 328
HI,
I'm working on a little practice applet to display numbers as a series of little boxes - like a 4 X 5 group of led's.
So I want to write a Convert method which will take in a digit as an int and then fill an array previously delcared but empty ( 0's) using a switch like this:

int[] squares = new int[20];
switch (numberToBeConverted)
{
case 0: squares = {0,1,1,0,1,0,0,1,1,0,0,1,1,0,0,1,0,1,1,0};
break;

etcetera.
Then another method would draw the squares or not based on the value in the index of the array.

However I can't seem to fill the array.

Any ideas please??

Thanks,
Terry


Raising Flares debut album 'Ignition' out now

http://www.raisingflares.com

Terry Doyle <br />SCPJ 1.4 , SCWCD , SCMAD(Beta)
Detlev Beutner
Ranch Hand

Joined: Jul 13, 2001
Posts: 76
This is a small problem... but solveable...
If you want a solution in a form that you can see all the segments each under each (for recognizing patterns) or just for an easier way to type in the values of the array, you can use this:

Otherwise you would have to access all segments you want to change one by one:

Hope it helps
Detlev
Terence Doyle
Ranch Hand

Joined: May 30, 2001
Posts: 328
Hi,
Thanks for the idea Detlev but I got it sorted out. I simply declared 9 arrays and then return the correct one for the digit recieved as a param.
However , were I to extend my experiment to letters and characters as well I think another solution for the storage of the info would be necessary.
Actually looking at the array they look like binary numbers... I wonder......??
int[] one = {0,0,1,0, 0,1,1,0, 0,0,1,0, 0,0,1,0, 0,1,1,1};
........perhaps I could store the relevant ints in a Map and access the binary equivalents....
Well, Enough thinking out loud. Let's get the numbers bit going first!!!
Thanks,
Terry
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Fill an array in a switch statement