+ 1
How to find even digits out of a given number? eg:2475
6 Respostas
+ 4
First take n as input
Then
while(n!=0)
{
d=n%10;
if(d%2==0)
System.out.println(d);
n=n/10;}
This will print the even nos of the no entered
+ 2
If x % 2 is 0, it is even.
+ 1
Thank you...
Is there any other way?
+ 1
Thanks ☺
0
uhm, I’m pretty tired, but if you’re looking to find even digits in a whole number, all that comes to mind is variable manipulation haha:
String num = "2475";
for(char c : num.toCharArray()){
int digit = Integer.parseInt(Character.toString(c));
if(digit % 2 == 0)
System.out.println(digit);
}
- 1
int[] nums = {2,4,7,5};
for(int num : nums) {
if(num % 2 == 0)
System.out.println(num);
}