Results 1 to 8 of 8
  1. #1
    janroz is offline Member
    Join Date
    Jan 2012
    Posts
    16
    Rep Power
    0

    Default 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

  2. #2
    janroz is offline Member
    Join Date
    Jan 2012
    Posts
    16
    Rep Power
    0

    Default 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

  3. #3
    KevinWorkman's Avatar
    KevinWorkman is online now Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,991
    Rep Power
    9

    Default 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?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  4. #4
    janroz is offline Member
    Join Date
    Jan 2012
    Posts
    16
    Rep Power
    0

    Default 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.

  5. #5
    janroz is offline Member
    Join Date
    Jan 2012
    Posts
    16
    Rep Power
    0

    Default 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
    {
    BufferedReader r = new BufferedReader(new InputStreamReader (System.in));
    int num;
    String ans, div;

    do{
    div = _____;
    System.out.print("Please enter an integer: ");
    num = Integer.parseInt(r.readLine());

    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.

  6. #6
    KevinWorkman's Avatar
    KevinWorkman is online now Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,991
    Rep Power
    9

    Default 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.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  7. #7
    janroz is offline Member
    Join Date
    Jan 2012
    Posts
    16
    Rep Power
    0

    Default 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.

  8. #8
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,091
    Rep Power
    20

    Default Re: can someone help me answer this problem please?

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

Similar Threads

  1. Compare true Answer /Player answer
    By Eilime in forum New To Java
    Replies: 1
    Last Post: 04-24-2011, 08:51 PM
  2. Replies: 3
    Last Post: 02-27-2011, 12:03 AM
  3. Could anyway answer me this?
    By Jojomofoman in forum New To Java
    Replies: 14
    Last Post: 12-16-2010, 11:14 PM
  4. What is the answer to this strange problem:
    By willemjav in forum New To Java
    Replies: 5
    Last Post: 08-11-2008, 09:31 PM
  5. What is the answer yo my problem with this code
    By masaka in forum New To Java
    Replies: 4
    Last Post: 03-26-2008, 06:33 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •