import java.util.Scanner;
class wloop
{ 
	public static void main(String[] args)
	{ 
int counter=2;
int sum=0;
while( counter<=200 )
{
sum = sum+counter ;
counter = counter+2;
}
System.out.println("The sum of integers from 2 to 200 is: " +sum);
 		}
 		}
import java.util.Scanner;
class wloop
{ 
    public static void main(String[] args)
    { 
        int sum=2;
        while (sum <=200)
        { 
        { 
        System.out.println(sum+ "");
        sum+=2;
         }
         }
         }
         }

the first code count out the even number 2 - 200 and the secound show the line 2 4 ... 200. but i dont know how to to it like its going to to it in 1 program like this.
2
4
.
200
The sum of integers from 2 to 200 is:
can anyone help me on how i can do it white out a if?

Recommended Answers

All 5 Replies

Didn't quite get your question... What EXACTLY are you looking for ?

i want the program to count out even number between 0 - 200 and sum up the numbers.
like this.
2
4
6
and so on
200
the sum of it is : 10100

Just print counter inside while loop of your first code. You will get
2
4
6 etc
Rest of the code seems fine

can you show me what you meen im new to this

System.out.println(sum+ "");
        sum+=2;

in your other class, you're doing actually the same as this, but there you are using counter.
so, copy-paste the print command in the other class, and change sum to counter.

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.