Questions:
- Write a program to calculate tax, given the following conditions:
- If income is less than 150000 then no tax
- If taxable income is in the range 150001 to 300000 then charge 10% tax
- If taxable income is in the range 300001 to 500000 then charge 20% tax
- If taxable income is above 500001 then charge 30% tax
- Write a program to enter the marks of a student in 4 different subjects. Then display the grade of the student as per the following conditions:
- If the average mark is greater than or equal to 90 then grade is O
- If the average mark is greater than equal to 80 but less than 90 then grade is E
- If the average mark is greater than equal to 70 but less than 80 then grade is A
- If the average mark is greater than equal to 60 but less than 70 then grade is B
- If the average mark is greater than equal to 50 but less than 60 then grade is C
- If the average mark is less than 50 then grade is F
- Write a program to calculate the roots of a quadratic equation.
- Write a program to enter a number from 1 to 7 and display the corresponding day of the week using switch statement.
- Write a program to find out the factorial of any inputted number.
- Write a program to check whether an inputted number is prime or not.
- Write a program to check whether an inputted number is palindrome or not.
- Write a program to find out the binary equivalent of any inputted decimal number.
- Write a program to display all Armstrong numbers from 1 to 10000.
- Write a program to find out the largest between two numbers using a conditional operator.
- Write a program to find out the largest between three numbers using the conditional operator.
- Write a recursive program to find the sum of n natural numbers. [ n is user input ]
- Write a recursive program to find the GCD of two inputted numbers.
Answers:
import java.util.Scanner;
class IncomeTax
{
public static double IncomeTaxCalc(double income)
{
double tax = 0;
if(income <= 150000)
tax = 0;
else if (income <= 500000)
tax = (150000 * 0.10) + ((income - 30000) * 0.20);
else
tax = (150000 * 0.10) + (200000 * 0.20) + ((income - 500000) * 0.30);
return tax;
}
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter your Income: ");
double income = sc.nextDouble();
System.out.println("Your Tax Ammount will be: " + IncomeTaxCalc(income));
}
}