0% found this document useful (0 votes)
11 views22 pages

Java Coding Questions

The document outlines various programming tasks and their corresponding inputs and outputs, covering a wide range of topics such as number manipulation, string processing, and data validation. Each task is presented with a sample input and expected output, illustrating how to solve specific problems using programming concepts. The tasks include operations like determining team assignments in cricket, password swapping, calculating factorials, and validating ticket numbers, among others.

Uploaded by

e22cs064
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views22 pages

Java Coding Questions

The document outlines various programming tasks and their corresponding inputs and outputs, covering a wide range of topics such as number manipulation, string processing, and data validation. Each task is presented with a sample input and expected output, illustrating how to solve specific problems using programming concepts. The tasks include operations like determining team assignments in cricket, password swapping, calculating factorials, and validating ticket numbers, among others.

Uploaded by

e22cs064
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

[Link] a cricket match, players are assigned to teams based on their jersey number.

If the number is even, the player joins Team


Blue; if odd, the player joins Team Red.
Sample Input:
Enter Jersey Number: 45
Sample Output:
Player with Jersey Number 45 is in Team Red.

2. Two friends entered their passwords incorrectly on each other’s login screen. Your job is to swap them back without using a
third variable.
Sample Input:
Enter First Password: 1234
Enter Second Password: 6789
Sample Output:
After swapping:
First Password = 6789
Second Password = 1234

3. Three new skyscrapers are being compared by height to select the “Tallest Building Award”.
Sample Input:
Enter height of Building A: 110
Enter height of Building B: 145
Enter height of Building C: 132
Sample Output:
Tallest Building is Building B with height 145.
[Link] ATM generates a secret verification code by adding up the digits of your entered PIN.
Sample Input:
Enter ATM Pin: 4529
Sample Output:
Secret Code = 20

5.A bus ticket number is sometimes printed backwards by mistake. Write a program that corrects it.

Sample Input:
Enter Ticket Number: 9876
Sample Output:
Correct Ticket Number is: 6789

6.A train ticket is called lucky if its number is the same forwards and backwards.

Sample Input 1:
Enter Ticket Number: 1221
Sample Output 1:
1221 is a Lucky Ticket.
Sample Input 2:
Enter Ticket Number: 6678
Sample Output 2:
5678 is NOT a Lucky Ticket.
7.A shopkeeper wants to know in how many ways he can arrange a certain number of products.
Sample Input:
Enter number of products: 5
Sample Output:
120

[Link] are building a learning app that shows the multiplication table of any number entered by the student.
Sample Input:
Enter a number: 7
Sample Output:
Multiplication Table of 7:
7x1=7
7 x 2 = 14
7 x 3 = 21
7 x 4 = 28
7 x 5 = 35
7 x 6 = 42
7 x 7 = 49
7 x 8 = 56
7 x 9 = 63
7 x 10 = 70
9.A calendar app needs to correctly decide whether February has 28 or 29 days, depending on leap year rules.

Sample Input 1:
Enter Year: 2024
Sample Output 2:
2024 is a Leap Year.

[Link] farmers want to divide their land into largest equal square plots without wasting land. The side of the square is
determined by the GCD of land’s length and width.

Sample Input:
Enter Land Length: 84
Enter Land Width: 36
Sample Output:
Greatest Common Divisor (GCD) = 12
Each square plot will have side length of 12.
11.A teacher is making a Math Worksheet for students and wants to list all prime numbers between 1 and 100.
Program Task: Print all prime numbers between 1 to 100.

Sample Output (Partial):


Prime Numbers between 1 and 100:
2 3 5 7 11 13 17 19 23 ... 97

12.A lock system opens only when you enter a special “Armstrong number” (like 153, where sum of cube of digits = number
itself).
Program Task: Check whether a given number is Armstrong.

Sample Input:
Enter number: 153
Sample Output:
153 is an Armstrong Number.

13.A farmer is studying rabbit population growth based on the Fibonacci sequence.

Sample Input:
Enter terms: 7

Sample Output:
0112358
[Link] accountant needs to total even-numbered invoices from 1 to 100.

Sample Output:
Sum of even numbers from 1 to 100 = 2550

15.A name tag printing machine prints names backward due to a bug. Write a program to restore names.

Sample Input:
hello

Sample Output:
olleh

16.A spell-check tool counts the number of vowels and consonants in a typed paragraph.

Sample Input:
Programming

Sample Output:
Vowels = 3
Consonants = 8
17.A search engine highlights the first unique character in a keyword.
Sample Input:
swiss

Sample Output:
w

18.A programmer is learning ASCII codes and wants to list values for English alphabets.
Sample Input:
A E
Sample Output (Partial):
A = 65
B = 66
...
E = 69

19.A text-to-speech engine detects vowels and consonants using switch or lookup tables.
Sample Input:
Enter character: e
Sample Output:
e is a Vowel.
Sample Input:
Enter character: t
Sample Output:
t is a Consonant.
20.A networking program needs to convert a decimal number to binary for data transmission, without library functions.
Sample Input:
Enter Decimal Number: 13
Sample Output:
Binary = 1101

21.A security system checks whether two passwords are made of the same letters (anagrams) to detect weak patterns.
Sample Input:
listen silent
Sample Output:
Anagrams

Sample Input:
hello world
Sample Output:
Not Anagrams

[Link] a payment system, credit card numbers should not contain spaces. Remove all white spaces from the input.
Sample Input:
4111 1111 1111 1111
Sample Output:
4111111111111111
23.A teacher wants to analyze the frequency of letters used in an essay for a language study.
Sample Input:
banana
Sample Output:
b=1, a=3, n=2

24.A puzzle game scrambles each word of a sentence by reversing them.


Sample Input:
Java is fun
Sample Output:
avaJ si nuf

25.A username system removes duplicate characters to generate a unique ID.


Sample Input:
programming
Sample Output:
progamin

[Link] editor tool highlights the longest word in a sentence for readability analysis.
Sample Input:
I love programming in Java
Sample Output:
programming
27.A music playlist system checks if two playlists are circular rotations of each other.
Sample Input:
abcde
Output:
cdeab

28.A resume builder tool automatically capitalizes the first letter of each word.
Sample Input:
welcome to java world
Sample Output:
Welcome To Java World

29.A find-and-replace feature in a text editor replaces a specific word throughout the document.
Sample Input:
I like Superman. Superman is powerful.
Sample Output:
I like Batman. Batman is powerful.

[Link] are analyzing the heights of students in a class. Write a program to find the tallest and shortest student.
Sample Input:
No. of Students :6
45 72 88 54 63 91
Sample Output:
Largest: 91
Smallest: 45
31.A shopkeeper wants to calculate the total and average sales of the week. Write a program to find the sum and average of
sales of the week.
Sample Input:
No. of the Weeks: 6
1200 1500 1800 1000 900
Sample Output:
Sum: 6400
Average: 1280.0

32.A playlist app wants to reverse the order of songs without creating a new list.
Sample Input:
No. of Songs: 5
12345
Sample Output:
54321

33.A teacher wants to know how many students scored a particular mark.

Sample Input:
No. of students: 7
10 20 10 30 10 40 20
Mark: 10
Sample Output:
3 times
[Link] online system stores old and updated stock ids. Check the old and updated both are same or not.
Sample Input: 5
12345
5
12345
Sample Output:
Same

35.A sports event records scores of players. Write a program to find the second-highest score.
Sample Input:
Scores:7
10 25 47 36 89 75
Sample Output:
Second Largest: 75

36.A system is storing user IDs but some IDs are repeated. Write a program to remove duplicate IDs from the list.
Sample Input:
7
5393571
Sample Output:
53971
[Link] different departments submit employee IDs. Write a program to merge both lists.
Sample Input:
3
135
3
246
Sample Output:
135246

[Link] a transaction system, 0 indicates failed transactions. The manager wants all successful transactions first while pushing
failed ones to the end.
Sample Input:
5
20805
Sample Output:
28500

39.A digital lock is designed such that it only opens when you enter a Strong Number (a number where the sum of factorials
of digits equals the number).
IP: 145
OP: Access Granted

IP: 123
OP: Access Denied
40.A playlist manager rotates songs after every k plays. Given an array of songs, simulate the rotation.
Sample Input & Output (Left Rotation):
IP:
5,
12345
k=2
OP: 3 4 5 1 2
Sample Input & Output (Right Rotation):
IP:
5
1 2 3 4 5,
k=2
OP: 4 5 1 2 3

41.A futuristic data system stores IDs in binary. An ID is valid only if its binary form is a palindrome. Write a program to
check this.
Sample Input & Output:
IP: 5
OP: Valid ID

IP: 10
OP: Invalid ID
[Link] a lucky draw, tickets are considered Buzz Numbers if the ticket number either ends with 7 or is divisible by 7. Write a
program to check if a ticket qualifies.
Sample Input & Output:

IP: 107
OP: Eligible

IP: 25
OP: Not Eligible

43.A mobile recharge app validates number by reducing it to a single digit sum using recursion.
IP: N = 9875
OP: Digital Root = 2
(9+8+7+5 = 29 → 2+9 = 11 → 1+1 = 2)

44.A dictionary search engine finds words using recursive binary search.
IP:
5
[10, 20, 30, 40, 50]
Key = 30
OP:
Found at index 2
45.A countdown timer prints numbers recursively.
IP: N = 5
OP: 5 4 3 2 1

46.A stock analysis app checks if prices are in order.


IP:
5
[1, 2, 3, 4, 5]
OP: In-Order
IP:
3
[5, 3, 1]
OP: Un-Order

46. A parking lot in a mall has RxC number of parking spaces. Each parking space will either be empty(0) or full(1). The
status (0/1) of a parking space is represented as the element of the matrix. The task is to find index of the prpeinzta row(R) in
the parking lot that has the most of the parking spaces full(1).
Note : Elements of the matrix M should be only 0 or 1.
Input :
3 -> Value of R(row)
3 -> value of C(column)
[0 1 0
110
1 1 1] -> Elements of the array M[R][C] where each element is separated by new line.
Output : 3 -> Row 3 has maximum number of 1’
47) A washing machine works on the principle of Fuzzy System, the weight of clothes put inside it for washing is uncertain
But based on weight measured by sensors, it decides time and water level which can be changed by menus given on the
machine control area. For low level water, the time estimate is 25 minutes, where approximately weight is between 2000
grams or any nonzero positive number below that.
For medium level water, the time estimate is 35 minutes, where approximately weight is between 2001 grams and 4000
grams. For high level water, the time estimate is 45 minutes, where approximately weight is above 4000 grams.
Assume the capacity of machine is maximum 7000 grams Where approximately weight is zero, time estimate is 0 minutes.
Write a function which takes a numeric weight in the range [0,7000] as input and produces estimated time as output is:
“OVERLOADED”, and for all other inputs, the output statement is “INVALID INPUT”.

Input should be in the form of integer value


Output must have the following format
Time Estimated: Minutes
Input value
2000
Output value
Time Estimated: 25 minute
[Link] Caesar cipher is a type of substitution cipher in which each alphabet in the plaintext or messages is shifted by a
number of places down the alphabet.
For example,with a shift of 1, P would be replaced by Q, Q would become R, and so [Link] pass an encrypted message from
one person to another, it is first necessary that both parties have the ‘Key’ for the cipher, so that the sender may encrypt and
the receiver may decrypt it.
Key is the number of OFFSET to shift the cipher alphabet. Key can have basic shifts from 1 to 25 positions as there are 26
total alphabets. As we are designing custom Caesar Cipher, in addition to alphabets, we are considering
numeric digits from 0 to 9. Digits can also be shifted by key places.
For Example, if a given plain text contains any digit with values 5 and keyy =2, then 5 will be replaced by 7, “-”(minus sign)
will remain as it is. Key value less than 0 should result into “INVALID INPUT”

Sample Input :
Enter your PlainText: All the best
Enter the Key: 1
Sample Output:
The encrypted Text is: Bmm uif Cft
48. A supermarket maintains a pricing format for all its products. A value N is printed on each product. When the scanner
reads the value N on the item, the product of all the digits in the value N is the price of the item. The task here is to design the
software such that given the code of any item N the product (multiplication) of all the digits of value should be
computed(price).

Input :
5244 -> Value of N
Output :
160 -> Price

Explanation:
From the input above
Product of the digits 5,2,4,4
5*2*4*4= 160
Hence, output is 160
[Link] intelligence agency has received reports about some threats. The reports consist of numbers in a mysterious method.
There is a number “N” and another number “R”. Those numbers are studied thoroughly and it is concluded that all digits of
the number ‘N’ are summed up and this action is performed ‘R’ number of times. The resultant is also a single digit that is yet
to be deciphered. The task here is to find the single-digit sum of the given number ‘N’ by repeating the action ‘R’ number of
times.
If the value of ‘R’ is 0, print the output as ‘0’. Explanation:
Example 1:
Here, the number N=99
Input :
99 -> Value of N
Sum of the digits N: 9+9 = 18
3 -> Value of R Repeat step 2 ‘R’ times i.e. 3 tims
Output : (9+9)+(9+9)+(9+9) = 18+18+18
9 -> Possible ways to fill the cistern. =54
Example 2: Add digits of 54 as we need a
Input : single digit 5+4
1234 -> Value of N Hence , the output is 9
2 -> Value of R
Output :
2 -> Possible ways to fill the cistern
50. There are total n number of Monkeys sitting on the branches of a huge Tree. As travelers offer Bananas and Peanuts, the
Monkeys jump down the Tree. If every Monkey can eat k Bananas and j Peanuts. If total m number of Bananas and p number
of Peanuts are offered by travelers, calculate how many Monkeys remain on the Tree after some of them jumped down to eat.
At a time one Monkeys gets down and finishes eating and go to the other side of the road. The Monkey who climbed down
does not climb up again after eating until the other Monkeys finish eating.
Monkey can either eat k Bananas or j Peanuts. If for last Monkey there are less than k Bananas left on the ground or less than
j Peanuts left on the ground, only that Monkey can eat Bananas(<k) along with
the Peanuts(<j).
Write code to take inputs as n, m, p, k, j and return the number of Monkeys left on the Tree.
Where, n= Total no of Monkeys
k= Number of eatable Bananas by Single Monkey (Monkey that jumped down last may get less than k Bananas)
j = Number of eatable Peanuts by single Monkey(Monkey that jumped down last may get less than j Peanuts)
m = Total number of Bananas
p = Total number of Peanuts
Remember that the Monkeys always eat Bananas and Peanuts, so there is no possibility of k and j having a value zero
Example 1:
Input Values
20
2
3
12
12
Output Values
Number of Monkeys left on the tree:1

You might also like