Results 1 to 2 of 2
  1. #1
    asadzarrar is offline Member
    Join Date
    Oct 2010
    Rep Power

    Default 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.

    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: " );
    6. a = ITI1120.readIntLine();

    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)");
    12. char again = ITI1120.readChar();
    13. System.out.println("Your final score is "+ score);

    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

  2. #2
    asadzarrar is offline Member
    Join Date
    Oct 2010
    Rep Power


    DOnt mind the little errors here and there...I'm aware of them.

Similar Threads

  1. Printing Two Dimensional Arrays with for loops
    By mcnam4119 in forum JCreator
    Replies: 3
    Last Post: 10-06-2010, 05:27 AM
  2. A few questions about arrays and loops
    By Jamison5213 in forum New To Java
    Replies: 1
    Last Post: 12-22-2009, 05:59 AM
  3. For loops and arrays throwing up errors
    By Banjo in forum New To Java
    Replies: 2
    Last Post: 11-25-2008, 06:40 AM
  4. [SOLVED] Arrays/for-loops (easy) need help.
    By Zebra in forum New To Java
    Replies: 7
    Last Post: 04-24-2008, 04:03 AM
  5. Some problems with arrays and loops
    By BHCluster in forum New To Java
    Replies: 3
    Last Post: 04-16-2008, 12:24 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts