# can someone help me answer this problem please?

• 01-05-2012, 05:04 PM
janroz
can someone help me answer this problem please?
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
• 01-05-2012, 05:10 PM
janroz
Re: can someone help me answer this problem please?
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
• 01-05-2012, 05:11 PM
KevinWorkman
Re: can someone help me answer this problem please?
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?
• 01-05-2012, 05:15 PM
janroz
Re: can someone help me answer this problem please?
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.
• 01-05-2012, 05:17 PM
janroz
Re: can someone help me answer this problem please?
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 = _____;
System.out.print("Please enter an integer: ");

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:

Please enter an integer: 5
The proper divisor(s) of 5 is/are: 1 5

Try Again? (yes/no): yes

Please enter an integer: 15
The proper divisor(s) of 15 is/are: 1 3 5 15

Try Again? (yes/no): yes

Please enter an integer: 25
The proper divisor(s) of 25 is/are: 1 5 25

Try Again? (yes/no): yes

Please enter an integer: 9
The proper divisor(s) of 9 is/are: 1 3 9

Try Again? (yes/no): no

Process completed.
• 01-05-2012, 05:20 PM
KevinWorkman
Re: can someone help me answer this problem please?
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.
• 01-05-2012, 05:23 PM
janroz
Re: can someone help me answer this problem please?
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.
• 01-05-2012, 06:43 PM
Tolls
Re: can someone help me answer this problem please?
Try using brackets for your loop:
Code:

```for (...) {   // do loop stuff in here. }```
That should highlight your problem.