Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: 2D array, at a loss.

  1. #1
    Junior Member
    Join Date
    May 2014
    Posts
    13
    Thanks
    3
    Thanked 1 Time in 1 Post

    Default 2D array, at a loss.

    Hey there,

    My assignment is to make a bowling game, however I'm not nearly there

    I wrote this bit:
    (Parser class just converts string to integer and returns it)
    public void shoot()
        { 
            for(int i = 0; i <10; i++)
            { 
     
                System.out.println("turn1");
                turns[i][0] = parser.getInput();
                if(turns[i][0] != 10)
                {
     
                    System.out.println("turn2");
     
                    turns[i][1] = parser.getInput();
     
            }
        }   
     
        }
    this seems to work,
    And now I am wondering how, and if I can control that the input does not exceed 10(10 pins),
    I tried doing this in my parser class, however I can't use an if statement there, since then I cannot return anything.
    (can I do this somehow?)

    Could anyone point me in the right direction?
    Thank you for your time.

    P.S, how do I go about changing my password on this site?
    Thank you for your time!


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,067
    Thanks
    47
    Thanked 2,146 Times in 2,119 Posts

    Default Re: 2D array, at a loss.

    control that the input does not exceed 10
    Read the input into a temp variable and compare its value to 10 in an if statement.
    If input > 10 don't accept it.
    If you don't understand my answer, don't ignore it, ask a question.

  3. The Following User Says Thank You to Norm For This Useful Post:

    Time4Java (May 22nd, 2014)

  4. #3
    Junior Member
    Join Date
    May 2014
    Posts
    13
    Thanks
    3
    Thanked 1 Time in 1 Post

    Default Re: 2D array, at a loss.

    Thank you, figured it out.
    now how do I change my password?
    Last edited by Time4Java; May 22nd, 2014 at 02:20 PM.

  5. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,067
    Thanks
    47
    Thanked 2,146 Times in 2,119 Posts

    Default Re: 2D array, at a loss.

    Can you provide more details about the problem you are having?
    If you don't understand my answer, don't ignore it, ask a question.

  6. #5
    Junior Member
    Join Date
    May 2014
    Posts
    13
    Thanks
    3
    Thanked 1 Time in 1 Post

    Default Re: 2D array, at a loss.

    Don't worry about it, it seems like all i run into are problems, eventually i'll figure them out!
    Thank you for your time though( and answer, helped me out quite a bit)

  7. #6
    Junior Member
    Join Date
    May 2014
    Posts
    13
    Thanks
    3
    Thanked 1 Time in 1 Post

    Default Re: 2D array, at a loss.

    I'm not sure if I should create a seperate thread per question, but since this leans towards this thread, I'l ask it here and hope for the best.
    If i have a 2d array: int[][], how can I convert this to a 2d array of strings ?

    Thank you for your time.

    --- Update ---

    Figured it out by writing it down again... shouldn't be so hasty to ask.
    English is not my native language (Typo alert).

Similar Threads

  1. Possible Loss of Precision
    By Canadian_Pirate in forum What's Wrong With My Code?
    Replies: 2
    Last Post: April 11th, 2011, 01:41 AM
  2. Possible loss of precision (double/int)
    By haloboy in forum What's Wrong With My Code?
    Replies: 6
    Last Post: March 8th, 2011, 01:23 AM
  3. [SOLVED] Loss of Precision (Double/Int)
    By Scotty in forum What's Wrong With My Code?
    Replies: 6
    Last Post: October 9th, 2010, 01:45 PM

Tags for this Thread