1. Member
Join Date
Jan 2012
Posts
16
Rep Power
0

Write a looping statement that will display the following output:

1.
4th Hello
6th Hello
8th Hello
10th Hello

2.
The sum of the first 10 integers is 55.
The average of the first 10 integers is 5.

3.
1 2 3 4 5
2 4 6 8 10
3 6 9 12 15
4 8 12 16 20
5 10 15 20 25

2. Member
Join Date
Jan 2012
Posts
16
Rep Power
0

for the first problem i used this code:

for(int i=4; i<=10; i++);
if (i % 2 ==0)
System.out.print(i + ""th Hello");

but it's not working

What exactly do you mean by "it's not working"? Do you see an Exception? Some strange behavior?

Hint: Where is the body of your for loop? Are you sure?

4. Member
Join Date
Jan 2012
Posts
16
Rep Power
0

yes exception is shown..

uhmm sir? can you help me solve this problem please? i know it is very easy for you to answer this problem. All of that problem need to use looping like do while i guess.

5. Member
Join Date
Jan 2012
Posts
16
Rep Power
0

i have also one problem here still not yet solve.. just need to insirt the correct loop in the blank:

import java.io.*;
public class Divisors2
{
public static void main(String [] args) throws IOException
{
int num;
String ans, div;

do{
div = _____;

for (int i=1; _______; i++) {
if (_________)
div = ______________+ " ";
}

System.out.println("The proper divisor(s) of " +num+ " is/are: " + div);
System.out.print("Try Again? (yes/no): ");
ans = _________________;
System.out.println();

} while(________________________________);
}
}

and the output should be like this:

The proper divisor(s) of 5 is/are: 1 5

Try Again? (yes/no): yes

The proper divisor(s) of 15 is/are: 1 3 5 15

Try Again? (yes/no): yes

The proper divisor(s) of 25 is/are: 1 5 25

Try Again? (yes/no): yes

The proper divisor(s) of 9 is/are: 1 3 9

Try Again? (yes/no): no

Process completed.

We can't just do your homework for you. I already gave you a hint. Where is your loop's body? Be especially mindful of misplaced semicolons.

7. Member
Join Date
Jan 2012
Posts
16
Rep Power
0

can you just give me example for divisors code sir please? :(
i haven't attended the class due to typhoon Washi hits our city(iligan city, philippines) that causes all our stuff and house destroyed by flash flood.
that is why i am looking for help in this forum.

8. Moderator
Join Date
Apr 2009
Posts
13,130
Rep Power
23

Try using brackets for your loop:
Java Code:
for (...) {
// do loop stuff in here.
}