ในบทความนี้ เราจะเข้าใจวิธีการคำนวณดอกเบี้ยแบบง่าย ดอกเบี้ยแบบง่ายคำนวณโดยใช้สูตรต่อไปนี้ ถ้าเงินต้น =P อัตรา =R% ต่อปี เวลา =T ปี:
Simple Interest (S.I) = P * T * R / 100
ความสนใจง่ายๆ − เปอร์เซ็นต์ดอกเบี้ยของเงินต้นทั้งหมด ผลตอบแทนน้อยกว่าเมื่อเทียบกับดอกเบี้ยทบต้น
ด้านล่างนี้เป็นการสาธิตสิ่งเดียวกัน -
ป้อนข้อมูล
สมมติว่าข้อมูลที่เราป้อนคือ −
Enter a Principle number : 100000 Enter a Interest rate : 5 Enter a Time period in years : 2
ผลผลิต
ผลลัพธ์ที่ต้องการจะเป็น −
Simple Interest : 1000
อัลกอริทึม
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
ตัวอย่างที่ 1
ที่นี่ ผู้ใช้ป้อนอินพุตตามข้อความแจ้ง คุณสามารถลองใช้ตัวอย่างนี้ในเครื่องมือกราวด์ของเรา
.
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);
}
} ผลลัพธ์
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
ตัวอย่างที่ 2
ในที่นี้ มีการกำหนดจำนวนเต็มก่อนหน้านี้ และเข้าถึงและแสดงค่าบนคอนโซล
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);
}
} ผลลัพธ์
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