Answer to Question #2851 in Java | JSP | JSF for thusang

Question #2851
Write a java application that prints all even numbers from 2 to 50 with the aid specifications:
*start new line after every multiple of 20.
*use for loop.
1
Expert's answer
2011-06-01T13:25:41-0400
class PrintEvenNumbers
{
public static void main(String[] args)
{
int x=2;
for (int i=2; i<=50; i+=2)
{
System.out.print(i+" ");
x+=2;
if (x>20)
{
System.out.println();
x=2;
};
};
};
};

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS