我有工作的程序,我只是需要帮助切断额外的数字,我不太善于使用printf语句时,在java打印。当我运行它时,我得到了类似1225.043的输出:
import java.util.Scanner;
public class Comparison {
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
float amount;
double principal = 1000.00;
double rate;
System.out.println("Enter interest rate");
rate = keyboard.nextDouble();
System.out.println("Year" +" "+ "Amount on deposit");
for(int year = 1; year <= 10; ++year)
{
amount = (float) (principal * Math.pow(1.0 + rate, year));
System.out.println(year+ " "+ amount);
System.out.println();
}
}
}
1条答案
按热度按时间ff29svar1#
尝试
输出: