Q. Write a JAVA program to display a number of even and odd digits available in a given Number?
package impprograms;
import java.util.Scanner;
public class FindEvenOdd {
public static void main(String[] args) {
int evendigit=0,oddigit=0;
Scanner scan=new Scanner(System.in);
System.out.println("Please Enter a Number :");
int val=scan.nextInt();
while(val!=0) {
int temp=val%10;
if(temp%2==0)
evendigit++;
else
oddigit++;
val=val/10;
}
System.out.println(" \n *** Total number of Even Digits of given number is : "+evendigit);
System.out.println(" \n *** Total number of Odd Digits of given number is : "+oddigit);
scan.close();
}
}
Note: you can drag the code workspace to see the complete code