How do you write algorithm to print first ten even numbers?

1 answer

Answer

1031211

2026-06-08 13:45

+ Follow

Maybe not the most elegant way but it works.

public class Main {

public static void main(String[] args) {

int count = 0;

int number = 2;

while(count < 10) { int c=0;

for(int i = 2; i < number ; i++)

{

if (number%i == 0)

{

c=1;

break;

}

}

if(c==0)

{

System.out.print(number + " ");

count++;

}

number++;

}//end of while

} //end of main

} //end of class

ReportLike(0ShareFavorite

Copyright © 2026 eLLeNow.com All Rights Reserved.