Loan java – Java Program to Calculate Remaining Loan Amount to Pay Back

Loan java: In the previous article, we have discussed about Java Program to Find the Product Between the Sum of Positive Numbers and Negative Numbers

In this article we will see how to calculate remaining loan amount to pay back by using Java programming language.

Java Program to Calculate Remaining Loan Amount to Pay Back

When some money is given to someone during his/her requirement that money is called as loan amount. The person/organization who gives this amount is called as lender and the person/organization  who takes the money is called as borrower.

Based on some condition the borrowed amount is repaid with in certain period of time.

For example:

You took 50000 rupees as loan from your friend without any interest. And till now you have repaid total 22000 rupees. So what is the rest amount that you need to repay. This can be calculated by subtracting the paid amount from total taken loan amount. So in this case 50000-22000 which is 28000 that you need to pay back to clear your loan amount completely.

Let’s see different ways to find remaining loan amount which needs to be repaid.

Method-1: Java Program to Calculate Remaining Loan Amount to Pay Back By Using Static Input Value

Approach:

  • Declare total loan amount and already paid amount.
  • Then subtract already paid amount from total loan taken amount which will the amount which needs to be repaid.
  • Print the result.

Program:

public class Main 
{
   public static void main(String args[])
   {
        //total loan amount declared
        int loanAmount = 25000;
        //already paid amount declared 
        int paidAmount = 11500;
        //calculating remaining loan amount that needs to be paid
        int remainingAmount = loanAmount - paidAmount;
        System.out.println("Remaining loan amount that you need to pay: "+ remainingAmount);
    }
}
Output:

Remaining loan amount that you need to pay: 13500

Method-2: Java Program to Calculate Remaining Loan Amount to Pay Back By Using User Input Value

Approach:

  • Take input of total loan amount and already paid amount from user by using Scanner class.
  • Then subtract already paid amount from total loan taken amount which will the amount which needs to be repaid.
  • Print the result.

Program:

import java.util.*;

public class Main 
{
   public static void main(String args[])
   {
        Scanner sc=new Scanner(System.in);
        //takihng input of total loan amount
        System.out.print("Enter total loan amount: "); 
        int loanAmount = sc.nextInt(); 
        //taking input of already paid amount
        System.out.print("Enter the amount you have already paid: "); 
        int paidAmount = sc.nextInt();
        //calculating remaining loan amount that needs to be paid
        int remaingAmount = loanAmount - paidAmount;
        System.out.println("Remaining loan amount that you need to pay: "+ remaingAmount);
   }
}
Output:

Enter total loan amount: 50000
Enter the amount you have already paid: 22000
Remaining loan amount that you need to pay: 28000

Method-3: Java Program to Calculate Remaining Loan Amount to Pay Back By Using User Defined Method

Approach:

  • Take input of total loan amount and already paid amount from user by using Scanner class.
  • Call a user defined method by passing total loan amount and already paid amount as parameter.
  • Then inside method, subtract already paid amount from total loan taken amount which will the amount which needs to be repaid.
  • Print the result.

Program:

import java.util.*;

public class Main 
{
   public static void main(String args[])
   {
        Scanner sc=new Scanner(System.in);
        //takihng input of total loan amount
        System.out.print("Enter total loan amount: "); 
        int loanAmount = sc.nextInt(); 
        //taking input of already paid amount
        System.out.print("Enter the amount you have already paid: "); 
        int paidAmount = sc.nextInt();
        //calling user defined method payback()
        payback(loanAmount, paidAmount);
   }
   
    public static void  payback(int loanAmount, int paidAmount)
    {
        //calculating remaining loan amount that needs to be paid
        int remainingAmount = loanAmount - paidAmount;
        System.out.println("Remaining loan amount that you need to pay: "+ remainingAmount);
    }
}
Output:

Enter total loan amount: 15000
Enter the amount you have already paid: 5000
Remaining loan amount that you need to pay: 10000

Explore complete java concepts from the Java programming examples and get ready to become a good programmer and crack the java software developer interview with ease.

Related Java Programs: