Results 1 to 5 of 5
  1. #1
    vctrm67 is offline Member
    Join Date
    Feb 2015
    Posts
    2
    Rep Power
    0

    Default Why can't Java run two methods?

    I'm new to Java, and I just created this script:

    public class HelloWorld {

    public static void main(String[] args) {
    String firstLine;
    String startUp;
    int hour, minute;
    hour = 9;
    minute = 15;
    firstLine = "I'm tired.";
    startUp = "Hello, World.";
    System.out.println(startUp);
    System.out.print("The time is now ");
    System.out.print(hour);
    System.out.print(":");
    System.out.print(minute);
    System.out.println(".");
    System.out.print(firstLine);


    }
    public static void newLine() {
    System.out.println("");
    }
    public static void procede(String[] args) {
    newLine();
    String history = "Today is Wednesday.";
    System.out.println(history);
    }
    }



    Every time I try to run this is eclipse, I only get the first part, so it reads in the console: "Hello, world. The time is now 9:15. I'm tired."
    I want it to read: "Hello, world. The time is now 9:15. I'm tired. (new line) Today is Wednesday."

    What am I doing wrong?

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,007
    Rep Power
    34

    Default Re: Why can't Java run two methods?

    Please edit the post and wrap the code in code tags to preserve the formatting and make the code more readable.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    Join Date
    Feb 2015
    Posts
    6
    Rep Power
    0

    Default Re: Why can't Java run two methods?

    Here's your code:
    Java Code:
    public class HelloWorld {
    
           public static void main(String[] args) {
                 
                  String firstLine;
                  String startUp;
                  int hour, minute;
                  hour = 9;
                  minute = 15;	
                  firstLine = "I'm tired.";
                  startUp = "Hello, World.";
                  System.out.println(startUp);
                  System.out.print("The time is now ");
                  System.out.print(hour);
                  System.out.print(":");
                  System.out.print(minute);
                  System.out.println(".");
                  System.out.print(firstLine);
    
    
           }
           public static void newLine() {
                   System.out.println("");
           }
           
           public static void procede(String[] args) {
                 newLine();
                 String history = "Today is Wednesday.";
                 System.out.println(history);
           }
    }
    You need to call the newLine and procede method into the main function. You created them in the HelloWorld class but you never call them in the main method. I could be wrong though.
    You also don't need the newLine() method, you could just use the procede method and use the System.out.println() function I think.
    Last edited by DesireToLearnJava; 02-14-2015 at 07:43 AM.

  4. #4
    vctrm67 is offline Member
    Join Date
    Feb 2015
    Posts
    2
    Rep Power
    0

    Default Re: Why can't Java run two methods?

    Quote Originally Posted by DesireToLearnJava View Post
    Here's your code:
    Java Code:
    public class HelloWorld {
    
           public static void main(String[] args) {
                 
                  String firstLine;
                  String startUp;
                  int hour, minute;
                  hour = 9;
                  minute = 15;	
                  firstLine = "I'm tired.";
                  startUp = "Hello, World.";
                  System.out.println(startUp);
                  System.out.print("The time is now ");
                  System.out.print(hour);
                  System.out.print(":");
                  System.out.print(minute);
                  System.out.println(".");
                  System.out.print(firstLine);
    
    
           }
           public static void newLine() {
                   System.out.println("");
           }
           
           public static void procede(String[] args) {
                 newLine();
                 String history = "Today is Wednesday.";
                 System.out.println(history);
           }
    }
    You need to call the newLine and procede method into the main function. You created them in the HelloWorld class but you never call them in the main method. I could be wrong though.
    You also don't need the newLine() method, you could just use the procede method and use the System.out.println() function I think.

    Anyone else? I tried what you said, but it doesn't work.

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,007
    Rep Power
    34

    Default Re: Why can't Java run two methods?

    it doesn't work
    Please explain.
    Please post the new code and the error messages it gives.
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. Replies: 1
    Last Post: 07-13-2012, 12:04 AM
  2. Replies: 2
    Last Post: 07-13-2012, 12:04 AM
  3. Replies: 8
    Last Post: 04-17-2012, 12:00 AM
  4. Java Noob, trying to call methods from another methods
    By gabrielpr12 in forum New To Java
    Replies: 8
    Last Post: 11-17-2011, 10:07 PM
  5. Replies: 1
    Last Post: 10-05-2011, 01:15 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
  •