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 9 of 9

Thread: need help and advice with my code

  1. #1
    Junior Member
    Join Date
    Jun 2017
    Posts
    8
    My Mood
    Worried
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default need help and advice with my code

    package task6;
     
     
    public class Task6 {
     
     
     
     
        public static void main(String  args [])
     {
            try
            {
                   int n = Integer.parse1nt(args[0]);
                   int n1 = Integer.parseint(args[1]);
                   int n2 = n+n1;
                   System.out.println("Sum is " + n2);
            } 
           catch(ArithmeticException ex)
           {
     
    		   System.out.println("ArithmeticException :"+"ex.getMessage()");
           }
           catch(NumberFormatException ex)
           {
     
               System.out.println("Format Exception:" + "ex.getMessage()");
     
           }
           catch(Exception ex)
           {
               System.out.println("Exception : " + "ex");
     
           }
     
        }
    }

    need you guys help with the correction of my java coding... I am kinda lost right now
    Last edited by DianaGalGot; June 7th, 2017 at 10:45 AM.

  2. #2
    Member
    Join Date
    May 2017
    Location
    Eastern Florida
    Posts
    68
    Thanks
    0
    Thanked 4 Times in 4 Posts

    Default Re: need help and advice with my code

    need you guys help with the correction of my java coding.
    Please explain.

    Copy and paste here the full text of any error messages you need help with.

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

    DianaGalGot (June 7th, 2017)

  4. #3
    Junior Member
    Join Date
    Jun 2017
    Posts
    8
    My Mood
    Worried
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: need help and advice with my code

    the coding doest give any error msg
    the output
    run:
    Exception : ex
    BUILD SUCCESSFUL (total time: 1 second)

  5. #4
    Member
    Join Date
    May 2017
    Location
    Eastern Florida
    Posts
    68
    Thanks
    0
    Thanked 4 Times in 4 Posts

    Default Re: need help and advice with my code

    the coding doest give any error msg
    Ok, do you have any specific java programming questions?

  6. #5
    Junior Member
    Join Date
    Jun 2017
    Posts
    8
    My Mood
    Worried
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: need help and advice with my code

    I not sure but base on my task we require to correct the error code..until it working that way I but confuse currently we got 6task on Java programming development.

     
    class excep2
    {
        public static void main(String  args [])
     {
            try
            {
                   int n = Integer.parse1nt(args[0]);
                   int n1 = Integer.parseint(args[1]);
                   int n2 = n+n1;
                   System.out.println("Sum is " + n2);
            } 
           catch(ArithmeticException ex)
           {
               System.out.println("ArithmeticException : “+ex.getMessage()); 
           }
           catch(NumberFormatException ex)
           {
               System.out.println("Format Exception: “+ex.getMessage()); 
           }
           catch(Exception ex)
           {
               System.out.pri  ntln("Exception : “ + ex ); 
           }
     
        }
    }
    this is the orginal code

  7. #6
    Member
    Join Date
    May 2017
    Location
    Eastern Florida
    Posts
    68
    Thanks
    0
    Thanked 4 Times in 4 Posts

    Default Re: need help and advice with my code

    What happens when you compile the code?

    Copy and paste here the full text of any error messages you need help with.

  8. #7
    Junior Member
    Join Date
    Jun 2017
    Posts
    8
    My Mood
    Worried
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: need help and advice with my code

     
     
    package task6;
     
     
    public class Task6 {
     
     
     
     
        public static void main(String  args [])
     {
            try
            {
                   int n = Integer.parseInt(args[0]);
                   int n1 = Integer.parseInt(args[1]);
                   int n2 = n+n1;
                   System.out.println("Sum is " + n2);
            } 
           catch(ArithmeticException ex)
           {
     
    		   System.out.println("ArithmeticException :"+ ex.getMessage());
           }
           catch(NumberFormatException x)
           {
     
               System.out.println("Format Exception:" + x.getMessage());
     
           }
           catch(Exception ex)
           {
               System.out.println("Exception : " + "ex");
     
           }
     
        }
    }


    hi i need help with the handling ArithmeticException using try-catch-finally exception. is my coding aree the right to handling ArithmeticException need an advice
    output
    run:
    Exception : ex
    BUILD SUCCESSFUL (total time: 0 seconds)

  9. #8
    Member
    Join Date
    May 2017
    Location
    Eastern Florida
    Posts
    68
    Thanks
    0
    Thanked 4 Times in 4 Posts

    Default Re: need help and advice with my code

    need help with the handling ArithmeticException
    What do you want the program to do when there is an ArithmeticException?
    Now it prints a message. Is that enough?

    Take a look at the tutorial: http://docs.oracle.com/javase/tutori...ons/index.html

  10. #9
    Member John Joe's Avatar
    Join Date
    Jun 2017
    Posts
    258
    My Mood
    Amused
    Thanks
    8
    Thanked 18 Times in 18 Posts

    Default Re: need help and advice with my code

    Are you sure your program can be run ? I run your code and get
    Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - cannot find symbol
    symbol: class out
    Shouldn't it be Integer.parseInt(args[x]) ?
    Whatever you are, be a good one

Similar Threads

  1. [SOLVED] I need some advice
    By KAJLogic in forum Java Theory & Questions
    Replies: 13
    Last Post: June 18th, 2014, 11:29 AM
  2. Throw Error - simple code.....any advice appreciated!
    By ziggy in forum What's Wrong With My Code?
    Replies: 5
    Last Post: June 6th, 2014, 08:01 AM
  3. [SOLVED] I need an advice
    By eyalfish in forum What's Wrong With My Code?
    Replies: 2
    Last Post: May 1st, 2014, 07:23 PM
  4. Hello, need some advice.
    By mango7777 in forum Member Introductions
    Replies: 1
    Last Post: June 15th, 2012, 08:10 AM
  5. Need some help/advice for my GUI code.
    By J-Ark in forum What's Wrong With My Code?
    Replies: 3
    Last Post: September 4th, 2010, 12:23 PM