programming forums Java Java JSRs Mobile Certification Databases Caching Books Engineering Languages Frameworks Products This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Sheriffs:
Saloon Keepers:
Bartenders:

# Fill an array in a switch statement

Terence Doyle
Ranch Hand
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.

Thanks,
Terry

Detlev Beutner
Ranch Hand
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
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

 Did you see how Paul cut 87% off of his electric heat bill with 82 watts of micro heaters?