Lab 2 (Conditional Statements)
Lab 2 (Conditional Statements)
Write a program that takes two numbers as input from users and print the largest among
them.
2. Write a program that checks if the number input by user is odd or even and display message
accordingly
3. Write a program that checks if the number input by user is divisible by 5 or not and display
message accordingly
4. Write a program that checks if the number input by user is both even and divisible by 5 or
not and display message accordingly.
(Note: Do try to write an algorithm and flowchart first before writing your code. It will
help you understand the flow of program.)
Resources: https://www.edrawsoft.com/explain-algorithm-flowchart.html (skip types of
algorithm)
5. Write a program to test if the character input by user is upper case or lower case or other
character.
6. Write a program to convert the case of character input by user. For example, if the user
inputs character ‘x’, output must be ‘X’
7. Write a program to input the annual income from user and compute the tax according to the
given conditions and display the total tax:
Total Annual Taxable Income Tax Rate
Upto Rs.1,00,000 No tax
From 1,00,001 to 1,50,000 10% of the income exceeding Rs.1,00,000
From 1,50,000 to 2,50,000 Rs.5000 +20% of the income exceeding Rs.1,50,000
Above Rs.2,50,000 Rs.25,000 +30% of the income exceeding Rs.2,50,000
8. Write a program to check whether the year input by user in leap year or not.
9. An electronics shop has announced the following seasonal discounts on the purchase of
certain items.
22. Write a Java program that reads in two floating-point numbers and tests whether they are the
same up to three decimal places.
Test Data
Input floating-point number: 1.256355
Input floating-point another number: 1.25621312
Expected Output :
They are same
23. Write a Java program that reads in two integer numbers and tests whether they are the same
up to three position starting from the least position.
Test Data
Input integer number: 123424256
Input integer another number: 3256
Expected Output :
They are same
24. Write a program that takes two numbers as input from users and print the largest among them
using ternary operator.
25. Write a program that checks if the number input by user is odd or even and display message
accordingly using ternary operator
26. Write a program that checks if the number input by user is divisible by 5 or not and display
message accordingly using ternary operator
27. Write a program that checks if the number input by user is both even and divisible by 5 or
not and display message accordingly using ternary operator.
28. Write a program to check whether the year input by user in leap year or not using ternary
operator.
29. Write a program that takes three numbers as input from users and print the largest among
them using ternary operator.
30. Write a Java program to find the number of days in a month
Input a month number: 2
Input a year: 2016
February 2016 has 29 days
31. Write a program to input the three sides of triangle and check if the sides of triangle are valid
or not. If the triangle is valid, print its type (scalene, isosceles, equilateral)