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

Thread: Output of 0 or 100?

  1. #1
    Member Scotty's Avatar
    Join Date
    Oct 2010
    Posts
    60
    My Mood
    Scared
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Default Output of 0 or 100?

    int newReading = 600;
    	int ReadingA = 780;
    	int ReadingB = 260;
     
     
    	double FinReading = ((newReading-ReadingB)/(ReadingA-ReadingB))*100;
     
    	System.out.print(FinReading);

    why is the output of this always 0.0 (or 0 if an int) instead of 65???


  2. #2
    Forum Squatter newbie's Avatar
    Join Date
    Nov 2010
    Location
    North Wales
    Posts
    661
    My Mood
    Stressed
    Thanks
    28
    Thanked 115 Times in 106 Posts
    Blog Entries
    1

    Default Re: Output of 0 or 100?

    Because 260 / 520 will return 0, and 0 * 100 is still 0
    Last edited by newbie; February 2nd, 2011 at 04:18 PM.
    Please use [highlight=Java]//code goes here...[/highlight] tags when posting your code

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

    Scotty (February 2nd, 2011)

  4. #3
    Member Scotty's Avatar
    Join Date
    Oct 2010
    Posts
    60
    My Mood
    Scared
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Default Re: Output of 0 or 100?

    Sorry, very tried, they all need to be doubles xD.

Similar Threads

  1. Help with output
    By jch02140 in forum What's Wrong With My Code?
    Replies: 6
    Last Post: January 8th, 2011, 12:09 PM
  2. what's the output?
    By dcshoecousa in forum Java Theory & Questions
    Replies: 3
    Last Post: November 27th, 2010, 10:11 AM
  3. Why am I getting this output?
    By ptabatt in forum What's Wrong With My Code?
    Replies: 5
    Last Post: August 6th, 2010, 07:36 PM
  4. need help with output.
    By VictorCampudoni in forum What's Wrong With My Code?
    Replies: 0
    Last Post: June 24th, 2010, 11:25 PM
  5. OutPut.
    By chronoz13 in forum Java Theory & Questions
    Replies: 3
    Last Post: August 29th, 2009, 10:54 AM