2b.hands-On - Control Flow Statements - Questions
2b.hands-On - Control Flow Statements - Questions
Hands-on No. : 2b
Date : 13.02.2025
Question
Question Detail Level
No.
1 Write a program to find the mobile chosen is within the budget Easy
or not. To find the budget mobiles is based on the below-
mentioned criteria,
a) If the cost of the mobile chosen is less than or equal to
15000 then display it as "Mobile chosen is within the
budget"
b) If the cost of the mobile chosen is greater than 15000
then display it as “Mobile chosen is beyond the
budget”
OUTPUT:
14000
Mobile chosen is within the budget
17000
Mobile chosen is beyond the budget
2 Write a program to check error in marks entry while user enters Easy
the marks in the system. Consider Error as marks entered less
than 0 and more than 100.
Sample Input: 83
Sample Input: -6
OUTPUT:
84
Valid entry
105
inValid entry
3 Kittu the ‘Giant Ant’ has 100 rooms in its colony. All the ants in Easy
the colony can crawl from 1 room to another, from there to
another and so on. But our ‘Kittu’ has a special power that
makes him to jump from one room to next 10th room directly.
Sample Input: 2
Sample output: 2 12 22 32 … 92
Sample Input: 5
Sample Output: 5 15 25 35 … 95
OUTPUT:
2
2 12 22 32 42 52 62 72 82 92
5
5 15 25 35 45 55 65 75 85 95
4 Once a baby lion lost his way in the jungle. An old deer took pity Easy
on him and planned to take him to his place. But the other deer
and his other friends — rabbits, squirrels, and birds are scared
so they accompanied. In the morning they counted themselves
to see if the baby lion done any mischief. Help them to find it.
Total number of animals, count of each (rabbit, deer, birds, and
squirrels) in the morning are the inputs.
OUTPUT:
Enter total: 270
Enter their counts: 34
65
87
24
Baby lion is mischevous
5 A store charges $12 per item if you buy less than 10 items. If you Easy
buy between 10 and 99 items, the cost is $10 per item. If you
buy 100 or more items, the cost is $7 per item. Write the logic
that asks customer name, how many items they are buying and
prints the customer’s name and total cost.
OUTPUT:
Madhi
50
Madhi 500
Sample Input: 2 2
Sample Output: 1
public static void main(String[] args) {
Scanner coordinate = new Scanner(System.in);
int x = coordinate.nextInt();
int y = coordinate.nextInt();
if(x<0) {
if(y<0) {
System.out.println("3");
}
else {
System.out.println("2");
}
}
else if(x>0) {
if(y>0) {
System.out.println("1");
}
else {
System.out.println("4");
}
}
else {
System.out.println("Origin");
}
}
OUTPUT:
3
-5
4
-2
8
2
}
}
OUTPUT:
100
50
Y
50% Allowed
8 A Strong Number is a number in which the sum of the factorial of each of Easy
its digits is equal to the number itself. For example, 145 is a strong
number because: 1!+4!+5!=1+24+120=145
OUTPUT:
145
Strong Number
178
Not a Strong Number
232
34543
4567654
567898765
OUTPUT:
5
1
2 3 2
3 4 5 4 3
4 5 6 7 6 5 4
5 6 7 8 9 8 7 6 5
1
11
121
1331
14641
OUTPUT:
4
1
1 1
1 2 1
1 3 3 1
OUTPUT:
Welcome
home
girl
W%lc%m%
h#m#
GIRL
12 A data company needs to store N files on a server. Each file has a Easy
specific size, and the server organizes these files into "buckets"
based on the sum of the digits of their file sizes.
For each file, you need to calculate its "bucket ID" based on the
sum of the digits of the file size. The bucket ID is determined by
summing all the digits in the file size.
Sample Input:
4
43 345 20 987
OUTPUT:
4
43
345
20
987
7 12 2 24
SampleInput N:7
minRange:3
maxRange :6
Values: 2 5 1 8 6 9 4 Sample Output
2189
OUTPUT:
N:
6
Enter minrange: 2
Enter maxrange: 9
3
5
1
3
9
15
1 9 15
OUTPUT:
81
48
34
25
16
15 You are a teacher creating an engaging math activity for your Easy
students by writing N numbers on the classroom whiteboard. You
use a green pen for odd numbers and a red pen for even
numbers.
Your task is to find and return an integer value representing the
number of times you need to switch from the green pen to the red
pen while writing these numbers.
SampleInput:
OUTPUT:
5
3
6
4
1
8