Computer >> Máy Tính >  >> Lập trình >> Java

Chương trình Java để tính lãi đơn giản

Trong bài này, chúng ta sẽ hiểu cách tính tiền lãi đơn giản. Tiền lãi đơn giản được tính theo công thức sau, Nếu Tiền gốc =P, Lãi suất =R% mỗi năm, Thời gian =T năm:

Simple Interest (S.I) = P * T * R / 100

Sở thích đơn giản - Lãi suất phần trăm trên tổng số tiền gốc. Lợi nhuận ít hơn so với Lãi gộp.

Dưới đây là một minh chứng về điều tương tự -

Đầu vào

Giả sử đầu vào của chúng tôi là -

Enter a Principle number : 100000
Enter a Interest rate : 5
Enter a Time period in years : 2

Đầu ra

Đầu ra mong muốn sẽ là -

Simple Interest : 1000

Thuật toán

Step 1 – START
Step 2 – Declare four float values principle, rate, time, simple_interest
Step 3 – Read values of principle, rate, time, from the user
Step 4 – Perform "(principle*rate*time)/100" to calculate the simple interest and store it in a
simple_interest variable
Step 8 – Display simple_interest
Step 10 – STOP

Ví dụ 1

Ở đây, đầu vào đang được người dùng nhập dựa trên lời nhắc. Bạn có thể thử trực tiếp ví dụ này trong công cụ nền tảng mã hóa của chúng tôi Chương trình Java để tính lãi đơn giản .

import java.util.Scanner;
public class SimpleInterest{
   public static void main (String args[]){
      float principle, rate, time, simple_interest;
      System.out.println("Required packages have been imported");
      Scanner my_scanner = new Scanner(System.in);
      System.out.println("A my_scanner object has been defined ");
      System.out.print("Enter a Principle number : ");
      principle = my_scanner.nextInt();
      System.out.print("Enter a Interest rate : ");
      rate = my_scanner.nextInt();
      System.out.print("Enter a Time period in years : ");
      time = my_scanner.nextInt();
      simple_interest = (principle*rate*time)/100;
      System.out.println("The Simple Interest is : " + simple_interest);
   }
}

Đầu ra

Required packages have been imported
A Scanner object has been defined
Enter a Principle number : 10000
Enter a Interest rate : 5
Enter a Time period in years : 2
The Simple Interest is : 1000.0

Ví dụ 2

Ở đây, số nguyên đã được xác định trước đó và giá trị của nó được truy cập và hiển thị trên bảng điều khiển.

public class SimplInterest{
   public static void main (String args[]){
      float principle, rate, time, simple_interest;
      principle = 100000;
      rate = 5;
      time = 2;
      System.out.printf("The Principle amount is %f \nThe interest rate is %f \nThe time period in years is %f " , principle, rate, time);
      simple_interest = (principle*rate*time)/100;
      System.out.println("\nThe Simple Interest is: " + simple_interest);
   }
}

Đầu ra

The Principle amount is 100000.000000
The interest rate is 5.000000
nThe time period in years is 2.000000
The Simple Interest is: 1000.0