Java problem

Discussion in 'Java' started by Nickmal2, Dec 26, 2019.

  1. Nickmal2

    Nickmal2

    Joined:
    Dec 26, 2019
    Messages:
    1
    Likes Received:
    0
    So I've always wanted to learn how to code and I've decided to take it up.
    -------------------------------------------------------------------
    public class D {

    public static void main(String[] args) {
    // TODO Auto-generated method stub



    }
    addExlamationMark("Hello there")
    public static void addExclamationMark(String s);{
    System.out.println(s + "!");
    }
    };

    -------------------------------------------------------------------
    I am trying to print a line where it says my "Hello there" but adds an exclamation mark.
    Like adding 2 strings together.
    -----------------
    Exception in thread "main" java.lang.Error: Unresolved compilation problem:

    at D.main(D.java:4)
    -------------------
    This is what the console tells me and i cant make it work.
    Sorry for being brain dead.
     
    Nickmal2, Dec 26, 2019
    #1
    1. Advertisements

  2. Nickmal2

    John Joe

    Joined:
    Apr 25, 2017
    Messages:
    131
    Likes Received:
    15
    Location:
    Malaysia
    You have lot of errors here.

    1. You should call addExlamationMark method inside main method.
    2. You named the method with two different names, one is addExlamationMark and another is addExclamationMark. I guess one is typo?

    The correct code should be

    Code (Java):
    public class D {

    public static void main(String[] args) {
      // TODO Auto-generated method stub
      addExclamationMark("Hello there");
    }

    public static void addExclamationMark(String s) {
        System.out.println(s + "!");
       }
    };
     
    John Joe, Dec 27, 2019
    #2
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.