Java Programming Problem

Discussion in 'OT Technology' started by doggfather, Jan 12, 2006.

  1. doggfather

    doggfather New Member

    Joined:
    Aug 6, 2005
    Messages:
    224
    Likes Received:
    0
    public class hw423 {
    public static void main(String[] args) {
    System.out.println( displayMessage(String hello,int 10) );
    }

    public static void displayMessage(String message,int times) {

    for (i=0; i <times; i++) {
    displayMessage = i;
    }
    return displayMessage;
    }

    }


    For some reaosn I cant get this to work. I want to type in lets say for displayMessage(String hello, 9), i'd like it to print "hello" 9 times
     
  2. MrMan

    MrMan New Member

    Joined:
    Jul 13, 2004
    Messages:
    308
    Likes Received:
    0
    well, there's a few mistakes.
    1. your displayMessage is a void, therefore it should not return anything. You're returning displayMessage.
    2. your print statements is not correct.
    3. you never initialized i and displayMessage.

    I'm not a Java programmer, but try this:

    public class hw423 {
    public static void main(String[] args) {
    String message = "hello";
    displayMessage(message, 10) ;
    }

    public static void displayMessage(String message,int times) {

    for (int i=0; i <times; i++) {
    System.out.println(message);
    }
    }
     
  3. doggfather

    doggfather New Member

    Joined:
    Aug 6, 2005
    Messages:
    224
    Likes Received:
    0
    thank you
     
  4. deusexaethera

    deusexaethera OT Supporter

    Joined:
    Jan 27, 2005
    Messages:
    19,712
    Likes Received:
    0
    Ah, I remember back when I used to come on here and ask for help with my homework...
     
  5. YoSmoovKid

    YoSmoovKid New Member

    Joined:
    Jul 21, 2005
    Messages:
    612
    Likes Received:
    0
    Location:
    Capitol of NJ
    Way back in 2004 no doubt...:hsd:
     
  6. sushibug

    sushibug :happysad:

    Joined:
    May 16, 2002
    Messages:
    3,096
    Likes Received:
    0
    Location:
    San Diego, CA
    i passed my first java class by copying others people work. its gonna bite me in the butt pretty good in two semesters when i start my upper div courses for my CS major.
     

Share This Page