Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,948 questions

51,890 answers

573 users

How to calculate simple interest in Java

2 Answers

0 votes
public class SimpleInterestCalculator {
    public static void main(String args[]) {
        float PrincipalAmount = 30000F;
        float Rate = 4F;
        float Years = 3F;
 
        float SimpleInterest = (PrincipalAmount * Rate * Years) / 100;
 
        System.out.print("Simple Interest is : " + SimpleInterest);
    }
}

 
 
 
/*
run:
 
Simple Interest is : 3600.0
 
*/

 



answered Nov 15, 2022 by avibootz
edited Aug 29, 2025 by avibootz
0 votes
public class SimpleInterestCalculator {

    // Method to calculate simple interest
    public static double calculateSimpleInterest(double principal, double rate, double years) {
        if (principal < 0 || rate < 0 || years < 0) {
            throw new IllegalArgumentException("Principal, rate, and time must be non-negative.");
        }
        return (principal * rate * years) / 100;
    }

    public static void main(String[] args) {

        try {
            // Input principal amount
            double principal = 30000F;

            // Input annual interest rate
            double rate = 4F;

            // Input time in years
            double years = 3F;

            // Calculate simple interest
            double simpleInterest = calculateSimpleInterest(principal, rate, years);

            // Display the result
            System.out.printf("The Simple Interest is: %.2f\n", simpleInterest);

        } catch (Exception e) {
            System.out.println("Invalid input. Please enter valid numeric values.");
        } 
    }
}

 

/*
run:

The Simple Interest is: 3600.00

*/

 



answered Aug 29, 2025 by avibootz

Related questions

1 answer 45 views
1 answer 57 views
1 answer 97 views
1 answer 125 views
125 views asked Nov 15, 2022 by avibootz
1 answer 122 views
122 views asked Nov 15, 2022 by avibootz
1 answer 116 views
116 views asked Nov 15, 2022 by avibootz
1 answer 137 views
137 views asked Nov 14, 2022 by avibootz
...