Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: What is wrong with my code.

  1. #1
    Junior Member
    Join Date
    Oct 2019
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default What is wrong with my code.

    I looked up some Java problems and made a code for one but it keeps giving the same error on the public classes
    import java.util.Scanner;
    public class NumbersDemo
    [{
    public static void main (String args[])
    {
    int a = 5;
    int b = 7;
    }
    public static void displayNumberPlus10(a) {
    System.out.println(a+10);
    }
    public static void displayNumberPlus10(b) {
    System.out.println(b+10);
    }
    public static void displayNumberPlus100(a) {
    System.out.println(a+100);
    }
    public static void displayNumberPlus100(b) {
    System.out.println(b+100);
    }
    public static void displayNumberPlus1000(a) {
    System.out.println(a+1000);
    }
    public static void displayNumberPlus1000(b) {
    System.out.println(b+1000);
    }
    public static void displayTwiceTheNumber(a) {
    System.out.println(a*2);
    }
    public static void displayTwiceTheNumber(b) {
    System.out.println(b*2);
    }

    }]

    It keeps giving me this error and I cant seem to fix it

    ----jGRASP exec: javac -g NumbersDemo.java
    NumbersDemo.java:9: error: <identifier> expected
    public static void displayNumberPlus10(a) {
    ^
    NumbersDemo.java:12: error: <identifier> expected
    public static void displayNumberPlus10(b) {
    ^
    NumbersDemo.java:15: error: <identifier> expected
    public static void displayNumberPlus100(a) {
    ^
    NumbersDemo.java:18: error: <identifier> expected
    public static void displayNumberPlus100(b) {
    ^
    NumbersDemo.java:21: error: <identifier> expected
    public static void displayNumberPlus1000(a) {
    ^
    NumbersDemo.java:24: error: <identifier> expected
    public static void displayNumberPlus1000(b) {
    ^
    NumbersDemo.java:27: error: <identifier> expected
    public static void displayTwiceTheNumber(a) {
    ^
    NumbersDemo.java:30: error: <identifier> expected
    public static void displayTwiceTheNumber(b) {
    ^
    8 errors

    ----jGRASP wedge2: exit code for process is 1.
    ----jGRASP: operation complete.



    Please help
    Last edited by Kyrocco; October 22nd, 2019 at 08:52 AM.

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: What is wrong with my code.

    NumbersDemo.java:9: error: <identifier> expected
    public static void displayNumberPlus10(a) {
    There needs to be a definition for the data type of the method's argument. For example:
    public static void displayNumberPlus10(int a) {


    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  3. The Following User Says Thank You to Norm For This Useful Post:

    Kyrocco (October 22nd, 2019)

  4. #3
    Junior Member
    Join Date
    Oct 2019
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: What is wrong with my code.

    Ok that fixed that error but now it gives the error, **error: method displayNumberPlus100(int) is already defined in class NumbersDemo**, for every (int b)

  5. #4
    Junior Member
    Join Date
    Oct 2019
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Help please

    I was writing some practice codes and keep getting the same error.


    import java.util.Scanner;
    public class NumbersDemo
    {
    public static void main (String args[])
    {
    int a = 5;
    int b = 7;
    }
    public static void displayNumberPlus10(int a) {
    System.out.println(a+10);
    }
    public static void displayNumberPlus10(int b) {
    System.out.println(b+10);
    }
    public static void displayNumberPlus100(int a) {
    System.out.println(a+100);
    }
    public static void displayNumberPlus100(int b) {
    System.out.println(b+100);
    }
    public static void displayNumberPlus1000(int a) {
    System.out.println(a+1000);
    }
    public static void displayNumberPlus1000(int b) {
    System.out.println(b+1000);
    }
    public static void displayTwiceTheNumber(int a) {
    System.out.println(a*2);
    }
    public static void displayTwiceTheNumber(int b) {
    System.out.println(b*2);
    }

    }



    I continue to get the error, ***error: method displayNumberPlus100(int) is already defined in class NumbersDemo***

  6. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: What is wrong with my code.

    method displayNumberPlus100(int) is already defined
    You can only define a method with the same arguments once in a class.

    Take a look at the tutorial: https://docs.oracle.com/javase/tutor...O/methods.html

    Look at how to use code tags again. the full text must be used not just a [
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. what's wrong with this code?
    By seyydi in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 27th, 2017, 05:45 PM
  2. There are something wrong with my code...
    By khanhnq in forum Object Oriented Programming
    Replies: 0
    Last Post: January 13th, 2013, 09:04 PM
  3. What is wrong with my code ?
    By rajarshi in forum What's Wrong With My Code?
    Replies: 0
    Last Post: January 11th, 2013, 10:54 PM
  4. what is wrong with my code
    By BLUEJ in forum Java Theory & Questions
    Replies: 4
    Last Post: January 11th, 2013, 04:40 PM
  5. what is wrong with my code
    By BLUEJ in forum What's Wrong With My Code?
    Replies: 4
    Last Post: January 10th, 2013, 07:52 PM

Tags for this Thread