0
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?

3
Contributors
5
Replies
6
Views
5 Years
Discussion Span
Last Post by stultuske
0

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

0

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

0
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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.