• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Fill an array in a switch statement

 
Terence Doyle
Ranch Hand
Posts: 328
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Detlev Beutner
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic