इस लेख में, हम साधारण ब्याज और चक्रवृद्धि ब्याज खोजने के लिए उपयोगकर्ता से मूल राशि, दर और समय (वर्ष) इनपुट करेंगे।
साधारण रुचि - कुल मूलधन पर प्रतिशत ब्याज। चक्रवृद्धि ब्याज की तुलना में रिटर्न कम है।
चक्रवृद्धि ब्याज - मूलधन और उपार्जित ब्याज पर लगाया जाने वाला प्रतिशत ब्याज। साधारण ब्याज की तुलना में दरें अधिक हैं।
इनपुट
मान लें कि निम्नलिखित हमारा इनपुट है -
Principal = 25000.0 Annual Rate of Interest = 10.0 Time (years) = 4.0
आउटपुट
साधारण और चक्रवृद्धि ब्याज की गणना के लिए हमारा आउटपुट निम्न होना चाहिए -
Simple Interest: 10000.0 Compound Interest: 11602.500000000007
एल्गोरिदम
Step 1 – START Step 2 – Declare 5 integers p, r, t, s_interest, c_interest Step 3 – Read values of p, r, t, from user Step 4 – Perform (p * r * t)/100 Step 5 – Perform p * Math.pow(1.0+r/100.0,t) - p; Step 6 – Store the output of Step 4 in s_interest Step 7 – Store the output of Step 5 in c_interest Step 8 – Display s_interest Step 9 – Display c_interest Step 10 – STOP
उदाहरण 1
यहां, उपयोगकर्ता द्वारा एक प्रॉम्प्ट के आधार पर इनपुट दर्ज किया जा रहा है। आप इस उदाहरण को हमारे कोडिंग ग्राउंड टूल में लाइव देख सकते हैं
।
import java.util.*;
public class SimpleAndCompountInterest{
public static void main(String []args){
double p, r, t, s_interest, c_interest;
Scanner scanner = new Scanner (System. in);
System.out.println("Enter the value of Principal = ");
p = scanner.nextDouble();
System. out. println("Enter the Annual Rate of Interest = ");
r = scanner.nextDouble();
System. out. println("Enter the Time (years) = ");
t = scanner.nextDouble();
s_interest = (p * r * t)/100;
c_interest = p * Math.pow(1.0+r/100.0,t) - p;
System.out.println("Simple Interest: "+s_interest);
System.out. println("Compound Interest: "+c_interest);
}
} आउटपुट
Enter the value of Principal = 1500 Enter the Annual Rate of Interest = 8 Enter the Time (years) = 3 Simple Interest: 360.0 Compound Interest: 389.568000000000
उदाहरण 2
यहां, पूर्णांक को पहले परिभाषित किया गया है, और इसके मान को एक्सेस किया जाता है और कंसोल पर प्रदर्शित किया जाता है।
import java.util.*;
public class SimpleAndCompountInterest {
public static void main(String []args){
double p, r, t, s_interest, c_interest;
p = 25000;
r = 10;
t = 4;
System.out.println("Principal = "+p);
System. out. println("Annual Rate of Interest = "+r);
System. out. println("Time (years) = "+t);
s_interest = (p * r * t)/100;
c_interest = p * Math.pow(1.0+r/100.0,t) - p;
System.out.println("Simple Interest: "+s_interest);
System.out. println("Compound Interest: "+c_interest);
}
} आउटपुट
Principal = 25000.0 Annual Rate of Interest = 10.0 Time (years) = 4.0 Simple Interest: 10000.0 Compound Interest: 11602.500000000007