When learning Python, you will work with different types of data, such as numbers, text, decimal values, and Boolean values. Python provides several built-in functions to help you work with these data types. One of the most useful functions is the type() function . The type() function tells you the data type of a value or variable. It helps you understand what kind of data Python is working with and can make debugging your programs easier. For example, consider these variables: age = 20 price = 99.50 name = "Rahul" is_student = True Although all four variables store data, their data types are different. Python allows us to check these types using type() . Let's understand how it works with simple examples. 1. What Is the type() Function in Python? The type() function is a built-in Python function that returns information about the type of an object. In beginner-level programming, you can use it to check whether a value is an integer, a floating-point number, a string,...
import java.util.Scanner;
public class IncomeTaxCalculator {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// Input salary from user
System.out.print("Enter your annual salary: ");
double salary = sc.nextDouble();
double tax = 0;
// Tax calculation based on salary slabs
if (salary <= 250000) {
tax = 0;
} else if (salary <= 500000) {
tax = (salary - 250000) * 0.05; // 5% tax
} else if (salary <= 1000000) {
tax = (250000 * 0.05) + (salary - 500000) * 0.20; // 20% tax
} else {
tax = (250000 * 0.05) + (500000 * 0.20) + (salary - 1000000) * 0.30; // 30% tax
}
// Display results
System.out.println("\n------------------------------");
System.out.println("Annual Salary: ₹" + salary);
System.out.println("Income Tax: ₹" + tax);
System.out.println("Net Salary after Tax: ₹" + (salary - tax));
System.out.println("------------------------------");
sc.close();
}
}
๐งฎ Example Output:
Enter your annual salary: 750000
------------------------------
Annual Salary: ₹750000.0
Income Tax: ₹62500.0
Net Salary after Tax: ₹687500.0
------------------------------
๐ Explanation:
-
If salary ≤ ₹2,50,000 → No tax
-
₹2,50,001 – ₹5,00,000 → 5% tax
-
₹5,00,001 – ₹10,00,000 → 20% tax
-
Above ₹10,00,000 → 30% tax
๐ Summary:
This Java program uses if-else conditions to calculate the income tax based on the Indian tax slabs and shows the net salary after tax deduction.
Comments
Post a Comment