CountDigits - int value, digit; Scanner sc = new...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
//******************************************************************** // CountDigits.java Author: Lewis and Loftus // // Solution to Programming Project 3.6 //******************************************************************** / import java.util.Scanner; i public class CountDigits { //----------------------------------------------------------------- // Counts the number of odd, even, and zero digits in an // integer input value. //----------------------------------------------------------------- public static void main (String[] args) { int oddCount = 0, evenCount = 0, zeroCount = 0;
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: int value, digit; Scanner sc = new Scanner(System.in); System.out.print ("Enter an integer value: "); value = sc.nextInt(); value = Math.abs (value); if (value == 0) zeroCount++; while (value > 0) { digit = value % 10; if (digit == 0) zeroCount++; else if (digit%2 == 0) evenCount++; else oddCount++; value = value / 10; } System.out.println ("Zero digits: " + zeroCount); System.out.println ("Even digits: " + evenCount); System.out.println ("Odd digits: " + oddCount); } }...
View Full Document

This note was uploaded on 05/17/2011 for the course COP 3530 taught by Professor Davis during the Spring '08 term at University of Florida.

Ask a homework question - tutors are online