G
G
Gleb Zubov2018-10-27 20:47:43
Java
Gleb Zubov, 2018-10-27 20:47:43

For loop in Java?

Let me explain the meaning of the problem!
It is necessary to make a task in Java, the essence is as follows:
1. Sum the numbers from 0 to 20
2. Summarize only even numbers from 0 to 20 and odd numbers.
Display larger result
3. If numbers of consecutive numbers need to be added so that their sum is greater than
1000
4. If even/odd numbers must be added to their sum is greater
than 1000
5. Display numbers from 0 to 100 by 4 in each line.
But the problem is that for some unknown reason, an error pops up in the code below (the problem occurs in the line " Sustem.out.println(run);" )

int run;
       run = 0;
       for (int j=0; j<21; j++)
       {
        run = run * j;
       }
       Sustem.out.println(run);

Thank you all in advance.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
EVGENY T., 2018-10-27
@Povedli

System.out.println("run = " + run);

L
Listening, 2018-11-12
@Listening

run = 0 and j=0.
every time you change j, and run remains the same as it was 0.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question