programming forums Java Java JSRs Mobile Certification Databases Caching Books Engineering OS Languages Paradigms IDEs Build Tools Frameworks Products This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Sheriffs:
Saloon Keepers:
Bartenders:

Loop Printing Out One Extra Line

Charles Doleba
Greenhorn
Posts: 1
Hey Everyone! So I have an assignment due where I have been given a set elements within an array that equal different mortgage interest rates. I have to create a program that prints out the highest mortgage with the year and the lowest mortgage with the year. After that, I have to print out the difference of mortgage rates and the change. I am able to figure everything out but the last part where it seems to print out the loop one more time.

I am currently getting the following output which is correct minus the -.3199999 at the end. How do I get that number to go away?

The average 30 year mortgage rate for the last 15 years was 5.48%
The maximum mortgage was 8.05% and the year was 2000
The maximum mortgage was 3.66% and the year was 2012
The decrease between 2000 and 2001 was 1.08%
The decrease between 2001 and 2002 was 0.43%
The decrease between 2002 and 2003 was 0.69%
The decrease between 2003 and 2004 was 0.01%
The increase between 2004 and 2005 was 0.03%
The increase between 2005 and 2006 was 0.54%
The decrease between 2006 and 2007 was 0.07%
The decrease between 2007 and 2008 was 0.31%
The decrease between 2008 and 2009 was 0.99%
The decrease between 2009 and 2010 was 0.35%
The decrease between 2010 and 2011 was 0.24%
The decrease between 2011 and 2012 was 0.79%
The increase between 2012 and 2013 was 0.32%
The increase between 2013 and 2014 was 0.19%
The decrease between 2014 and 2015 was 0.32%
-0.31999999999999984

Junilu Lacar
Sheriff
Posts: 11494
180
• 1
Your change() method returns the value of sub. That value is passed to the System.out.println() statement on line 15.

Junilu Lacar
Sheriff
Posts: 11494
180
• 1
Do you need to use the value of sub outside of the change method? I don't see any place where you do that. You can therefore declare the return value of change() as void and remove that last line with the return statement. From main, you can then just call the change() method directly without surrounding it with System.out.println().

Junilu Lacar
Sheriff
Posts: 11494
180
• 1
... and Welcome to the Ranch!