HW2.12

时间:2025-02-02 12:04:20

HW2.12

控制台:

 import java.util.Scanner;

 public class Solution
 {
     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.nextDouble();
         double interestRate = input.nextDouble();

         input.close();

         double interest = balance * interestRate / 1200;

         System.out.println("The interest is " + interest);
     }
 }

对话框:

 import javax.swing.JOptionPane;

 public class Solution
 {
     public static void main(String[] args)
     {
         String balanceString = JOptionPane.showInputDialog(null, "Enter balance",
             "Balance", JOptionPane.QUESTION_MESSAGE);
         double balance = Double.parseDouble(balanceString);

         String interestRateString = JOptionPane.showInputDialog(null, "Enter interest rate",
             "Interest Rate", JOptionPane.QUESTION_MESSAGE);
         double interestRate = Double.parseDouble(interestRateString);

         double interest = balance * interestRate / 1200;
         String output = "The interest is " + interest;

         JOptionPane.showMessageDialog(null, output);
     }
 }

相关文章