Thread: Home work

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    2
    Rep Power
    0

    Home work


    hi am totally new to java. am tryin to finish this homework but can't firgure whats wrong with this error. can anyone help

    // This application displays some math facts

    {
    public static void main(String args[])
    {
    int a = 2, b = 5, c = 10;
    add = (a + b);
    add = (b + c);
    subtract = (c - a);
    }
    public static void add(int a, int b)
    {
    System.out.println("The sum of " + a +
    " and " + b + " is " + (a + b));
    }
    public static void subtract(int a, int b)
    {
    System.out.println("The difference between " +
    a + " and " + b + " is " + (c - a));
    }
    }
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2011
    Posts
    41
    Rep Power
    0
    your need identifiers before add and substract

    you can't have two variables with the same nameint a = 2, b = 5, c = 10;
    int add = (a + b);
    int add2 = (b + c);
    int subtract = (c - a);
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    2
    Rep Power
    0
    Originally Posted by Lottoplus
    your need identifiers before add and substract

    you can't have two variables with the same nameint a = 2, b = 5, c = 10;
    int add = (a + b);
    int add2 = (b + c);
    int subtract = (c - a);
    well it complied but it wont show result . its supposed to show something like the the sum of a and b is 7... isn't it suupposed to show the out,when you have ....System.out.println()


    Code:
    { public static void main(String args[]) { Scanner bucky = new Scanner(System.in); int a = 2, b = 5, c = 10; int add = (a + b); add = (b + c); int subtract = (c - a); } public static void add(int a, int b) { System.out.println("The sum of " + a + " and " + b + " is " + ( add )); } public static void subtract(int c, int a) { System.out.println("The difference between " + c + " and " + a + " is " +subtract); } }
  6. #4
  7. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,711
    Rep Power
    347
    it wont show result
    Where is the println() that is supposed to show the result?
    When will it be executed?

    Please edit your post and wrap the code in code tags to preserve formatting and make it easier to read.
  8. #5
  9. Java Junkie
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jan 2004
    Location
    Mobile, Alabama
    Posts
    4,021
    Rep Power
    1285
    Are you invoking the methods that print?
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    18
    Rep Power
    0
    Originally Posted by bullet
    Are you invoking the methods that print?
    it looks like you're trying to call methods with specific functions.

    if you say

    int add = 6 + 5

    you'll get a variable add <- 11

    if you want your method to do the work, you would say

    add(parameter1,parameter2)

    and then your add method would do it's thing
  12. #7
  13. No Profile Picture
    Permanently Banned
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    8
    Rep Power
    0
    As users install Java to third-party applications and a variety of applications across different platforms, and we follow the issues that are often reported and error codes that they send to us.

IMN logo majestic logo threadwatch logo seochat tools logo