So I'm trying to define a counter in a while loop, and print it from the class:
public class odd
{
public static void main(String[] args)
{
System.out.println("Input your number");
int x = IO.readInt();
int odd = 0;
int even = 0;
while (x != 0)
{
if (x % 2 !=0)
{
odd = odd++;
}
else
{
even = even++;
}
x = IO.readInt();
}
System.out.println(even + "evens" + odd + "odds");
}
}
Anyone know how I can print the variables even and odd?
This program is attempting to take a continuous input of numbers from a user, and output the number of odds and evens:
We wish to develop a program that will count the number of even and odd integers in a set ("even" meaning divisible by 2, "odd" meaning not divisible by 2). We will use zero as an indicator that the set has been completely entered, and this zero should not be counted as part of the set. Ask the user for a sequence of integers, terminated by zero. Output the number even integers and the number of odd integers.
***IO is a module that we were provided with to read inputs and return errors***