2. WAP IN JAVA TO INPUT A NUMBER WHICH CONSIST OF THREE DIGITS , DISPLAY TOTAL NUMBER OF EVEN DIGITS FROM IT .
import java.util.*; //import java packages
class Prog //declare the class
{
public static void main(String args[ ]) // “main” method
{
Scanner ob=new Scanner(System.in);
int num; //declare the variable
System.out.print(“Enter the number”); //input the value
num=ob.nextInt( ) ;
int x1=num%10; //extract the digits
num=num/10 ;
int x2=num%10;
int x3=num/10;
int count=0;
if((x1%2)==0) //check for Even digits and Count
count++;
if((x2%2)==0)
count++;
if((x3%2)==0)
count++;
System.out.prinln(“Total Even digits :”+count); //display total number of digits
} //end of “main”
} //end of class
No comments:
Post a Comment