Computer Science, asked by sairohith42p9fofu, 1 year ago

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?
QGP: C,C++, JAVA, Python, etc ???
sairohith42p9fofu: python
QGP: Ahh well. I'm afraid I won't be able to help. I know only JAVA. Anyways
sairohith42p9fofu: ok can u send me in java
QGP: Yes. I will first type it and try on my computer. Then I will post here. Is that fine?
sairohith42p9fofu: ya sure
QGP: Okay. Getting to work

Answers

Answered by QGP
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+", ");
                }
            }
        }
    }
}

sairohith42p9fofu: by the way I wrote the python programme can I give me suggestions to run app like given in JAVA
sairohith42p9fofu: l = []
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))
QGP: So you want to know where you can run Python? Are you asking about Python IDEs??
sairohith42p9fofu: yup :)
QGP: I have heard that PyCharm, PyDev and Wing IDE are some good ones. PyCharm is I think the more popular one
sairohith42p9fofu: i heard of anaconda prompt whats ur suggestion in it
QGP: Dunno. Never used it
QGP: I haven't ever programmed in Python. I just gave you what I knew about it. That's it :)
QGP: Saw some images. PyCharm looks way better than Anaconda Prompt.
sairohith42p9fofu: :)
Similar questions