Displaying even numbers

Hey guys, this is my first time on here and I hope you can help :)

My problem is that I need to make the following peice of code display only even numbers, does anyone have any idea how?

Thank you.

//Akash Thakkar

import java.io.*;

class NewLoop

{

public static void main (String[] args) throws IOException

{

BufferedReader stdin = new BufferedReader (new InputStreamReader (System.in));

String inputData;

int count, limit;

System.out.println ("Enter an integer:"); //User inputs starting value

inputData = stdin.readLine();

count = Integer.parseInt (inputData);

System.out.println ("Enter another integer:"); //User imputs limit

inputData = stdin.readLine();

limit = Integer.parseInt (inputData);

for (count = count; count > limit; count--) //If the count is bigger than the limit, count downwards in decrements of 1

{

System.out.println (count + " ");

}

for (count = count; count <= limit; count++) // If the count is smaller than or equal to the limit, count upwards in increments of 1

{

System.out.println (count + " ");

}

for (count = count; count == limit; count = count) //If the count is equal to the limit, don't count up or down

{

System.out.println (count + " ");

}

}

}

[1383 byte] By [Brown_Thundera] at [2007-10-2 20:27:12]
# 1
If the number is divided by 2 and the remainder is zero, it's even. Java provides the modulus operator (%) for that purpose.if (number % 2 == 0) {System.out.println(number);}
mvantuyla at 2007-7-13 23:10:04 > top of Java-index,Java Essentials,New To Java...
# 2
If the number is odd, add/subtract one. Then you can increment/decrement by two.~
yawmarka at 2007-7-13 23:10:04 > top of Java-index,Java Essentials,New To Java...
# 3
> If the number is divided by 2 and the remainder is zero, it's even. Another way is to "AND" the number with 1 and check if the result is zero.~
yawmarka at 2007-7-13 23:10:04 > top of Java-index,Java Essentials,New To Java...
# 4

Thank you very much, but could you be more specific please? :)

I'm pretty new to java so I hope you can understand I'm having some trouble here.

For the peice of code above in particular, what should I do to display only even numbers and where should I put it?

Thank you once again for your help.

Brown_Thundera at 2007-7-13 23:10:04 > top of Java-index,Java Essentials,New To Java...
# 5

> Thank you very much, but could you be more specific

> please? :)

int i = 3;

if (i % 2 == 1) i++;

while (i < 20) { // prints even numbers 4 through 18

System.out.println(i);

i += 2;

}

> For the peice of code above in particular, what

> should I do to display only even numbers and where

> should I put it?

You'll need to adapt the concepts listed above to your code. Good luck!

~

yawmarka at 2007-7-13 23:10:04 > top of Java-index,Java Essentials,New To Java...
# 6

This loop is pointless.

//If the count is equal to the limit, don't count up or down

for (count = count; count == limit; count = count)

{

System.out.println (count + " ");

}

The initializer "count=count" is redundant, as is the loop change (second "count=count"). If count==limit, then the loop will go on forever. If count != limit, the loop won't do anything at all.

MLRona at 2007-7-13 23:10:04 > top of Java-index,Java Essentials,New To Java...