Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Find all numbers that are odd and divisible by 17 within 0-5 million

Input is 0-5 million

Find all numbers within the input that are:
Odd

Divisible by 17

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Output those numbers

This is what I have for now, not sure how to proceed:

  for (int i = 0; i < 5000001; i++) {
 if (i % 2==0){

I’m sure that the for loop needs to be used, not sure how to find if it’s divisible by 17.
There was a similar question on here already, however it was in python.

>Solution :

Here is the code :-

 int num = 0;
        while(num +17 <= 5000000){
            num = num +17;
            if(num % 2 == 0){
                System.out.print(num+ " ");
            }
        }
        System.out.println("Done");
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading