第2章:财务应用程序:计算利息 【控制台输出】

来源:互联网 发布:ttc 轴体 知乎 编辑:程序博客网 时间:2024/04/30 11:06
/** * 财务应用程序:计算利息。 * 读取收支余额和年百分率(yearRate): * 1)使用控制台进行输入和输出。 * 2)使用对话框获取输入和显示输出。 * 利息额(interest) = 收支余额(balance) * (年利率 / 1200)。 * 下面是一个运行示例: * —————————————————————————————————————————————————————————————— * | Enter balance and interest rate (e.g., 3 for 3%): 1000 3.5 | * | The interest is 2.91667                                    | * —————————————————————————————————————————————————————————————— */package Test;import java.util.Scanner;public class T212Scanner {public static void main(String[] args) {Scanner input = new Scanner(System.in);System.out.print("Enter balance and interest rate (e.g., 3 for 3%): ");double balance = input.nextInt();double yearRate = input.nextDouble();double interest = balance * (yearRate / 1200);System.out.println("The interest is " + interest);}}


原创粉丝点击