i created a loop and it doesn't run:

for ( int i = 0; i < 100; i++)
{
    for( int j = 0; j < 100; j++);
    {
          int total = i + j;
        }
        System.out.println( total );
    }
for( int j = 0; j < 100; j++);

in line 4 there should be no semicolon ; there

Member Avatar for hfx642

It will run... IF you get it to compile!
Once you implement zeroliken's fix, it STILL won't compile.
Declare your variable "total" on line #1 instead of line #6.

I assume you want to display 0+0 to 99+99. But it only displays the sum of i and 99 because the variable total keeps on changing value 100 times and its final value is its last value which is the sum i and 99.
You can run this code either.

for(int i = 0; i < 100; i++)
{
    for(int j = 0; j < 100; j++)
    {
        int total = i + j;
        System.out.println(total);
    }
}

Hope I could help.

In line 4, there should be no semicolon because you are stating an if-statement. You should use curly braces either.

In line 4, there should be no semicolon because you are stating an if-statement. You should use curly braces either.

congratulations ...
you just made two posts full of information already provided by zeroliken and hfx642.
if there was something like copyrights on this forum, you would be f*cked ==>> (plagiarism isn't just a fancy word)

provide new info, new improvements, or allow credit to be given to those who came up with the solution first.

I'm sorry. I didn't read their posts. I quit!

my post was not an attempt to make you "quit" or stop helping people, everyone here (me included) appreciates the attempt, but in a lot of cases the OP is not as familiar with Java development as the rest of us.

if everyone goes double posting answers, pretty soon we'll have threads spread over ten pages, what won't exactly encourage 'newbies' to read all the answers, while they are given the idea all answers should be read.

you would be f*cked

What I hate most in your post is that phrase. Can you just remind me without this! I'm irritated!

i created a loop and it doesn't run:

for ( int i = 0; i < 100; i++)
{
    for( int j = 0; j < 100; j++);
    {
          int total = i + j;
        }
        System.out.println( total );
    }

total variable should be declared before the starting of loop atleast before inner loop
since the variable doesn't have scope in the line
System.out.println( total );
so declare the variable total as below

for ( int i = 0; i < 100; i++)
{
    int total=0;
    for( int j = 0; j < 100; j++);
    {
         total = i + j;
        }
        System.out.println( total );
    }

this coding may work good

i created a loop and it doesn't run:

for ( int i = 0; i < 100; i++)
{
    for( int j = 0; j < 100; j++);
    {
          int total = i + j;
        }
        System.out.println( total );
    }

hey there Jerry:

The problem is that you are re-declaring you variable 'total' for every loop it does therefore this should produce only the asnswer 100 in 'total' once the loop has completed?

Declare your variable total before any loop begins like so:

int total =0;
for ( int i = 0; i < 100; i++)
{
    for( int j = 0; j < 100; j++);
    {
          total = i + j;
        }
        System.out.println( total );
    }

and merry xmas to daniweb and all its subscribers!!!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.