我叫王超然,是一名电脑爱好者,现在在新加坡留学上高一.我立志成为一名电脑人才,愿意在这里与大家一同分享我玩转电脑的心得.O-level华文考了A-One哈哈!
天气: 晴朗
心情: 高兴
/*P3Q7
* Wang Chaoran
* Description:7 (Computing future tuition)
Suppose that the tuition for a university is $10,000 this year and increases 5% every year. Write a program that
uses a loop to compute the tuition in ten years,
computes the total cost of four years' worth of tuition starting ten years from now.
*/
import java.text.DecimalFormat;
public class P3Q7
{
public static void main(String[]args)
{
//Number of decimal place
DecimalFormat df = new DecimalFormat("0");
System.out.printf("%-10s%-10s\n","Year","Tuition fee");
double sum=0;
double tuition=10000;
//print the table
for(int i=1;i<11;i++)
{
tuition=tuition*(1+0.05);
System.out.printf("%-10s%-10.2f\n",i,tuition);
}
//print the fee
for(int i=11;i<15;i++)
{tuition=tuition*(1+0.05);
sum+=tuition;
}
System.out.print("Total cost of four years' worth of tuition starting ten years from now is: ");
System.out.printf("%-10.2f",sum);
}
}
导入论坛查看(33)回复(0)引用(0)好评(0) 差评(0)
加入收藏
编辑
审核
TAG:
computing