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

Thread: Clarification

  1. #1
    Junior Member
    Join Date
    Aug 2017
    Posts
    23
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Question Clarification

    I've been reading this book and it had this code.


    27 double totalPayment = monthlyPayment * numberOfYears * 12;
    28
    29 // Display results
    30 System.out.println("The monthly payment is $" +
    31 (int)(monthlyPayment * 100) / 100.0);
    32 System.out.println("The total payment is $" +
    33 (int)(totalPayment * 100) / 100.0);
    34 }
    35 }

    I just don't understand what is the purpose of the (int) in S.O.P

    I mean the value itself is double, doesn't that satisfy it ?

    EXAMPLES* of some cases to where these can be applied ?


    Thank you in advance!
    Last edited by UniverseCloud; June 1st, 2018 at 12:22 PM.

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Clarification

    purpose of the (int)
    That is a cast. It changes the value to an int. What prints when the code is executed?
    Remove the (int), compile and execute it to see what the difference is.
    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:

    UniverseCloud (June 1st, 2018)

Similar Threads

  1. SOLID Principles clarification and help with Classes and Methods
    By nicsxox in forum Object Oriented Programming
    Replies: 2
    Last Post: February 6th, 2018, 01:19 PM
  2. Replies: 2
    Last Post: November 23rd, 2013, 12:34 AM
  3. Clarification needed for addActionListener and actionPerformed
    By mabelanger in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 7th, 2013, 09:03 PM
  4. [SOLVED] NullPointerException.CLARIFICATION
    By chronoz13 in forum Exceptions
    Replies: 8
    Last Post: August 28th, 2009, 03:24 PM