hey guys i a m a beginner to programming (trying to become a CS major). so far i feel like in the group of people in class who are behind with the rest of the class. Most of these kids seem to have prior knowledge in programming i do not.
Any helpful hints for me to use to become better at programming and to also Ace this class would be much appreciated.
Anywaysi am trying 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). zero should be used as an indicator that the set has been completely entered, and this zero should not be counted as part of the set
so far this is what i have come up with.
public class EvenOdd {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.print("Enter number of values (int>=1)");
int n = IO.readInt();
while (n<1){
System.out.print("Number must be >=2");
n = IO.readInt();
}
int counteven=0,countodd=0;
System.out.print("Enter first number");
int number = IO.readInt();
if (number % 2 == 0){
counteven++;
}else if (number %2 !=0);{
countodd++;
System.out.println("count of even numbers is " + counteven + ".");
System.out.println("count of odd numbers is " + countodd + ".");
I am using eclipse. When i run the program and enter "2" it says not an integer and to try again. then when i enter ten it tell me that my count for even is 1 and count for odd is 1 as well. This should not happen.