How can I round the first few even numbers to two zeros?
public class MoneyDriver
{
public static void main( String[] args )
{
int a = 2011;
int b = 21;
double c = 2200.00;
double d = 31500.00;
System.out.println( "Year" + "\t" + "Age" + "\t" + "Balance at end of year" +
"\t" + "Income adjusted for inflation" );
for( int r = 1; r < 10; r++)
{
double e = Math.round(c * 100.0) / 100.0;
double f = Math.round(d * 100.0) / 100.0;
System.out.println( a + "\t" + b + "\t" + e + "\t" + f );
a = a + 1;
b = b + 1;
c = ( c + 2000 ) * 1.1;
d = ( d * 1.05 );
}
}
}
Currently this gives me the output of:
Year Age Balance at end of year Income adjusted for inflation
2011 21 2200.0 31500.0
2012 22 4620.0 33075.0
2013 23 7282.0 34728.75
2014 24 10210.2 36465.19
2015 25 13431.22 38288.45
2016 26 16974.34 40202.87
2017 27 20871.78 42213.01
2018 28 25158.95 44323.66
2019 29 29874.85 46539.85
I assume once the decimals are fixed on the first four, the tabbing will right itself.
I AM NEW TO JAVA! I do not know complicated things.. and was wondering if there was an easy fix that didn't add on much code at all.
Thank you!