0% found this document useful (0 votes)
31 views1 page

Input A Number and Check Whether All Digits Are Even or Not Using While Loop in Java Dremendo

The document discusses a Java program that takes a user-input number and uses a while loop to check if all the digits in the number are even. It provides the full code for the program, which initializes variables to count the total digits and even digits. It uses the modulo and division operators in a while loop to extract each digit and check if it is even. It then prints a message indicating whether all digits were even or not based on comparing the total and even digit counts.

Uploaded by

AADITYA SINGH
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views1 page

Input A Number and Check Whether All Digits Are Even or Not Using While Loop in Java Dremendo

The document discusses a Java program that takes a user-input number and uses a while loop to check if all the digits in the number are even. It provides the full code for the program, which initializes variables to count the total digits and even digits. It uses the modulo and division operators in a while loop to extract each digit and check if it is even. It then prints a message indicating whether all digits were even or not based on comparing the total and even digit counts.

Uploaded by

AADITYA SINGH
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

  More   

Input a number and


check whether all
digits are even or not
using while loop in
Java
while Loop - Question 12

   

Flutter Dynamic theme change using getX | Dark …

In this question, we will see how to input a


number and check if all digits in the number
are even digit or not in Java programming
using while loop. To know more about while
loop click on the while loop lesson.

Q12) Write a program in Java to input a


number and check if all digits in the number
are even digit or not using while loop.

Program

Copy
import java.util.Scanner;

public class Q12

public static void main(String args


{
int n,d,td=0,ed=0;
Scanner sc=new Scanner(System.

System.out.print("Enter any numbe


n=sc.nextInt();

while(n>0)
{
d=n%10;
if(d%2==0)
{
ed=ed+1; // counti
}
td=td+1; // counti
n=n/10;
}

if(td==ed)
{
System.out.println("All digit
}
else
{
System.out.println("All digit
}
}

Output

Enter any number 6248


All digits are even digit

 Previous Next 

···

For over a decade, Dremendo has been recognized


for providing quality education. We proudly
introduce our newly open online learning platform,
which o!ers free access to popular computer
courses.

Our Courses

 C Tutorial

 C++ Tutorial

 Java Tutorial

 Python Tutorial

 HTML Tutorial

 CSS Tutorial

News Updates

Enter Your Email


Flutter Dynamic theme change using ... Subscribe

   !


©Do you
2024 like cookies?
Dremendo. We use cookies to ensure
All Rights Reserved.
you get the best experience on our website.
Pricing Refund and Cancellation About Us
Contact PrivacyLearn
Policymore
Terms I agree

You might also like