SELF PRACTICE
SDE Readiness Training
Practice No. : 2a
Topic : Introduction to Java
Date : 13.02.2025
Solve the following problems
Question
Question Detail Level
No.
1 Determine whether to sleep in based on two conditions: 'weekday' Easy
and 'vacation'. If it's not a weekday or if we're on vacation, we
sleep in. Write Java code to determine whether we sleep in or not.
Sample Input: false false
Sample Output: true
Sample Input:true false
Sample Output: false
Sample Input: false true
Sample Output: true
2 Determine whether we are in trouble based on the smiling status Easy
of two monkeys, 'aSmile' and 'bSmile'. We are in trouble if both
monkeys are smiling or if neither of them is smiling. Return true if
we are in trouble
Sample Input: false false
Sample Output: true
Sample Input: true true
Sample Output: true
Sample Input: false true
Sample Output: false
Sometimes later becomes never. DO IT NOW!
1
SELF PRACTICE
SDE Readiness Training
3 We have a loud-talking parrot. The "hour" parameter is the current Easy
hour time in the range 0..23. We are in trouble if the parrot is
talking and the hour is before 7 or after 20. Print true if we are in
trouble.
Sample Input: 6 true
Sample Output: true
Sample Input: 7 true
Sample Output: false
Sample Input: 6 false
Sample Output: false
4 We're hosting a party with tea and candy. The outcome of the Easy
party is encoded as follows: 0=bad, 1=good, or 2=great. A party
is considered good (1) if both tea and candy are at least 5. If either
tea or candy is at least double the amount of the other one, the
party is great (2). However, if either tea or candy is less than 5,
the party is always bad (0).
Sample Input: 6 8
Sample Output: 1
Sample Input: 3 8
Sample Output: 0
Sample Input: 20 6
Sample Output: 2
5 Given 2 non-negative ints, a and b, return their sum, so long as Easy
the sum has the same number of digits as a. If the sum has more
digits than a, just return a without b.
Sample Input: 2 3
Sample Output: 5
Sample Input: 8 3
Sample Output: 8
Sometimes later becomes never. DO IT NOW!
2
SELF PRACTICE
SDE Readiness Training
6 Given an int n, return the string form of the number followed by Easy
"!". So the int 6 yields "6!". Except if the number is divisible by 3
use "Fizz" instead of the number, and if the number is divisible by
5 use "Buzz", and if divisible by both 3 and 5, use "FizzBuzz".
Note: the % "mod" operator computes the remainder after
division, so 23 % 10 yields 3. What will the remainder be when
one number divides evenly into another?
7 Write a Java program to reverse a 3-digit number. Easy
8 Write a Java program to calculate Net Salary. User must input Easy
Basic Salary and Output should be net salary calculated based on
the following allowances:
Allowances:
DA = 70% of Basic Salary
HRA = 7% of Basic Salary
MA = 2% of Basic Salary
TA = 4% of Basic Salary
Deduction:
PF = 12% of Basic Salary
Income/professional tax = User Input (e.g., 500)
Net Salary = Basic Salary + Allowances – Deduction
Sometimes later becomes never. DO IT NOW!
3