English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Can someone help me with this Java question please...... write a program using the “for” loop that counts off all the numbers 1, 2, 3, 4, ..., 19, 20, but only print out the numbers that are even

Thanks

2007-11-10 22:08:57 · 6 answers · asked by HeH 2 in Computers & Internet Programming & Design

6 answers

//the for loop
for(i=0;i<=20;i++)
if((i%2)==0)
system.out.Println(i);//check this statementfor correctness
// iam'nt sure about the output statement

2007-11-10 22:15:11 · answer #1 · answered by puneeth cva 2 · 1 0

I am giving you the for loop segment

for(i=1;i<=20;i++)
{
if(i%2==0)

System.out.println(i);
}

2007-11-10 22:18:38 · answer #2 · answered by Shariq (http://coinsindia.info) 5 · 0 0

use the condition

if(no%2==0)
System.out.println(no);

2007-11-10 22:14:05 · answer #3 · answered by DeAd MaN 4 · 1 0

for (int x = 1; x < 21; x++) if (x % 2 == 0) Sop(x);

You are in deep trouble if you have problem here.

2007-11-10 22:16:13 · answer #4 · answered by Andy T 7 · 0 0

use a conditional branch for your print; divide your output by 2 and check for a remainder
now code this yourself!

2007-11-10 22:12:41 · answer #5 · answered by Anonymous · 0 1

?

2007-11-10 22:10:45 · answer #6 · answered by Thankful 1 · 0 2

fedest.com, questions and answers