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.


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

Results 1 to 3 of 3

Thread: java rounded sum

  1. #1
    Junior Member
    Join Date
    Dec 2013
    Thanked 0 Times in 0 Posts

    Question java rounded sum

    write a program which accepts three integers as command line arguments.Round each number to the next multiple of 10,If the right most digit is 5 or more,otherwise round it down to previous multiple of 10.

    For example: 15 and 17 round up to 20 where as 12 round up to 10.

    calculate and print the sum of these rounded values.

    tell me logic if you know

  2. #2
    Super Moderator
    Join Date
    Jun 2013
    So. Maryland, USA
    My Mood
    Thanked 698 Times in 680 Posts

    Default Re: java rounded sum

    You tell us first.

  3. #3
    Member andbin's Avatar
    Join Date
    Dec 2013
    Thanked 122 Times in 114 Posts

    Default Re: java rounded sum

    Quote Originally Posted by harvind View Post
    tell me logic if you know
    First, command line arguments are String values. Do you know how to parse (convert) a String into an int?
    Second, in the Java SE framework there is no method to "round" a number at multiples of the unit (eg. 10, 100 etc..). There are rounding methods in Math class but they round at decimals level. The rounding at multiples of 10 is up to you and there is more than one possibility. All you need are the standard operators / % +. Eventually with a test using an if.

    Try and post your code and ask for eventual problems.
    Andrea, www.andbin.net SCJP 5 (91%) SCWCD 5 (94%)

    Useful links for Java beginners My new project Java Examples on Google Code

  4. The Following User Says Thank You to andbin For This Useful Post:

    harvind (December 20th, 2013)

Similar Threads

  1. Replies: 2
    Last Post: October 25th, 2013, 06:31 AM
  2. sum of digits
    By snarayana.murthy86 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: July 18th, 2013, 02:40 PM
  3. Sum of intervals
    By cisneros778 in forum Java Theory & Questions
    Replies: 3
    Last Post: February 21st, 2012, 04:08 PM
  4. Cumulative sum of entries
    By CSUTD in forum What's Wrong With My Code?
    Replies: 9
    Last Post: November 1st, 2011, 06:32 PM
  5. [SOLVED] Java program to generate 10 random integers and then sum computed
    By Lizard in forum What's Wrong With My Code?
    Replies: 1
    Last Post: May 14th, 2009, 12:33 PM