Write a program, which will find all such numbers between 1000 and 3000 (both included) such that each digit of the number is an even number.
The numbers obtained should be printed in a comma-separated sequence on a single line.
QGP:
Which programming language do you want it in?
Answers
Answered by
6
public class EvenDigits
{
public static void main(String[] args)
{
for(int i=1000;i<=3000;i++)
{
int n=i;
if(n%2==0)
{
int d1 = n%10; //d1 becomes units digit
n = n/10;
int d2 = n%10; //d2 becomes tens digit
n = n/10;
int d3 = n%10; //d3 becomes hundreds digit
n = n/10;
int d4 = n; //d4=n is now the thousands digit
if((d1%2==0)&&(d2%2==0)&&(d3%2==0)&&(d4%2==0))
{
System.out.print(i+", ");
}
}
}
}
}
{
public static void main(String[] args)
{
for(int i=1000;i<=3000;i++)
{
int n=i;
if(n%2==0)
{
int d1 = n%10; //d1 becomes units digit
n = n/10;
int d2 = n%10; //d2 becomes tens digit
n = n/10;
int d3 = n%10; //d3 becomes hundreds digit
n = n/10;
int d4 = n; //d4=n is now the thousands digit
if((d1%2==0)&&(d2%2==0)&&(d3%2==0)&&(d4%2==0))
{
System.out.print(i+", ");
}
}
}
}
}
for i in range(1001,3000):
if (i%2==0 and (i/10)%2==0 and (i/100)%2==0 and (i/100)%2==0):
l.append(str(i))
print(",".join(l))
Similar questions