If his basic salary is less than Rs. 1500, then HRA=10% of basic salary and DA=25% of basic. If his salary is either equal to or above Rs. 1500, then HRA=Rs. 500 and DA=50% of basic. If the employee’s salary is input through the keyboard write a program to find his gross salary. Create program in java

				
					import java.util.Scanner;

public class SalaryCalculator {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        // Input basic salary from user
        System.out.print("Enter the basic salary: ");
        double basicSalary = scanner.nextDouble();

        double HRA;
        double DA;

        // Calculate HRA and DA based on the basic salary
        if (basicSalary < 1500) {
            HRA = 0.10 * basicSalary;
            DA = 0.25 * basicSalary;
        } else {
            HRA = 500;
            DA = 0.50 * basicSalary;
        }

        // Calculate gross salary
        double grossSalary = basicSalary + HRA + DA;

        // Display the gross salary
        System.out.println("The gross salary is: " + grossSalary);
    }
}

				
			
prime number

Explanation:

  1. Import Scanner: We import the Scanner class to take input from the user.
  2. Main method: We define the main method where the execution begins.
  3. Input basic salary: We prompt the user to enter their basic salary and read this value using the Scanner object.
  4. HRA and DA Calculation:
    • If the basic salary is less than Rs. 1500, HRA is 10% of the basic salary, and DA is 25% of the basic salary.
    • If the basic salary is Rs. 1500 or more, HRA is Rs. 500, and DA is 50% of the basic salary.
  5. Gross Salary Calculation: Gross salary is the sum of the basic salary, HRA, and DA.
  6. Output: Finally, we print the gross salary.

You can run this program in any Java IDE or a command-line environment to test with different basic salary values.

Scroll to Top