统计信息

  • 访问数:11156
  • 博客数:142
  • 建立时间:2008-01-05
  • 更新时间:2008-05-21
我叫王超然,是一名电脑爱好者,现在在新加坡留学上高一.我立志成为一名电脑人才,愿意在这里与大家一同分享我玩转电脑的心得.O-level华文考了A-One哈哈!

P3Q7

2008-01-30 17:41:19

天气: 晴朗 心情: 高兴

/*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);
   
  }
}

 


加入收藏 编辑 审核

TAG: computing

我来说两句

OPEN

Powered by X-Space 1.2 © 2001-2006 Comsenz Technology Ltd