Created
November 13, 2013 17:52
-
-
Save joeyv/7453355 to your computer and use it in GitHub Desktop.
Tells how many zeros,odd, & even numbers there is in a user inputted number.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
public class OddNum{ | |
public static void main(String []args){ | |
int num; | |
int odd = 0, even = 0, zero = 0; | |
Scanner scan = new Scanner(System.in); | |
num = scan.nextInt(); | |
System.out.println (num); | |
while (num >= 1) { | |
if (num % 10 == 0) { | |
zero += 1; | |
} else if (num % 2 == 0) { | |
even += 1; | |
} else if (num % 2 != 0){ | |
odd += 1; | |
} | |
num /= 10; | |
} | |
System.out.println ("odds = " + odd + "\n even = " + even + "\n zero = " + zero); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment