2
import java.util.Random;
public class RandomHomework
{
    public static void main(String[] args)
    {
        int i;
        Random generator = new Random();
        double randomDecimals = generator.nextDouble()-.04;
        int randomNumber = generator.nextInt(9)+10;
        for(i = 0; i > 100; i++)
        {
            if(randomNumber >= 10.00)
            {
                System.out.println(randomNumber + randomDecimals);
            }
        }
    }
}

I am having a problem with the setup of my for loop and cannot figure it out... It runs perfectly fine when I remove the for loop.

As you can see I tried declaring the i previously but it made no difference.

Ismail Badawi
  • 36,054
  • 7
  • 85
  • 97

6 Answers6

12
for(i = 0; i > 100; i++)

This says: start with i set to zero and continue as long as it is greater than 100.

This stops right away

laune
  • 31,114
  • 3
  • 29
  • 42
3

The problem is the condition of the loop

for(i = 0; i > 100; i++)

The condition should be i < 100

viczap
  • 194
  • 2
  • 12
1

Your loop condition is always false. You start from i = 0 and say run while i > 100. However, 0 is never > 100 so your loop never happens.

Change

for(i = 0; i > 100; i++)

To

for(i = 0; i < 100; i++)
nem035
  • 34,790
  • 6
  • 87
  • 99
1

You must change:

for(i = 0; i > 100; i++)

to:

for(i = 0; i < 100; i++)

for the loop to execute.

drage0
  • 372
  • 3
  • 8
0

You should use

for(i = 0; i < 100; i++)

instead of

for(i = 0; i > 100; i++)

else it would end as soon as it starts since you are checking i > 100

Community
  • 1
  • 1
Rahul Tripathi
  • 168,305
  • 31
  • 280
  • 331
-1

You need to use for(i =0; i<100; i++) cuz your version is ended right away

wwood
  • 489
  • 6
  • 19