How to use arrays and loops?

• 11-01-2010, 12:04 AM
How to use arrays and loops?
HI, I want to know how one can write a program so that it can identify the integer value in an array and act accordingly.

i.e.
1. int [] a;
2. int index;
3. int dice, position, score = 0;
4. char y = 1, n = 0;
5. System.out.println( "Please input the array of the game board: " );

7. for (int index=0;;index++)
{
8. dice = generator.nextInt(6);
9. System.out.println("The number of steps was "+ dice);
10. System.out.println("You moved in position "+ position +" and you gain "+ dice + " points");
11. System.out.println("Do you want to move again? (y/n)");
13. System.out.println("Your final score is "+ score);
}
}
}

Explanation:
line 8 is a dice generator (1-6)
line 6 means Array of integers is user inputed

Outline: example array ={1,2,3,4,0,5,6}
Dice rolls,
number of steps are taken respectively,
points acheived depending on which element user lands on
(ie. roll=3, steps=3, points=4 (total pt=4)),
ask for another shot (wanna roll again (y/n) (y) ),
repeat (roll 2, steps=2, point=0).

Since user landed on 0, System.out.println "GameOver",
Otherwise the points add on until user selects (n)

The main issue I struggle with is the looping back of the points so that they add on.
And the how to identify y and n (boolean? or Char? or String?)

Thanks for any help in advance
• 11-01-2010, 12:04 AM