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 5 of 5

Thread: how to?

  1. #1
    Junior Member
    Join Date
    Nov 2011
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default how to?

    I have to let the user press in a number, and the number that is being inserted is the amount that the program has to run.

    so i have this already

    System.out.println("How many simulations do you want");
    numberSimulations = Input.readLong();

    for ( y = 0 ; y = numberSimulation ; y ++) {
    SimulationThatHasToBeDoneXNumberOfTimes();

    this way doesn't work because it has to be boolean,can anyone tell me another way of doing this??

  2. #2
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,511
    My Mood
    Grumpy
    Thanks
    0
    Thanked 165 Times in 156 Posts

    Default Re: how to?

    y = numberSimulation

    A single equals is assignment. A double equals is comparison. Do you really want the loop to execute ONLY when y equals numberSimulation?
    Improving the world one idiot at a time!

  3. #3
    Junior Member
    Join Date
    Nov 2011
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: how to?

    if the input is 100, the loop has to be done 100 times but i don't think for is the right way.
    i have to run SimulationThatHasToBeDoneXNumberOfTimes(); an amount of times==>that amount is chosen by the user(input)

  4. #4
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,511
    My Mood
    Grumpy
    Thanks
    0
    Thanked 165 Times in 156 Posts

    Default Re: how to?

    I understand, I want you to think about it. If numberSimulation is 100 and y is 0 what should the condition of your loop be?
    Improving the world one idiot at a time!

  5. #5
    Junior Member
    Join Date
    Nov 2011
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: how to?

    y <= number

    thank you very much