Nothing Special   »   [go: up one dir, main page]

Java Test - Day 1 - July 1

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 54

JAVA TEST _ IT DEPT _ JULY 1

Test Summary
 No. of Sections: 1
 No. of Questions: 20
 Total Duration: 180 min
Section 1 - CODING
Section Summary
 No. of Questions: 20
 Duration: 180 min
Additional Instructions:
None
Q1.
Problem Statement

Jim is a little scientist. He has planned to design software to track all his work. As
part of this requirement, he needs to move all the uppercase letters to the end of
the sentence and print the remaining letters without changing the order. He wants
your help to complete the task.

Write a program to move all the uppercase letters to the end of the string.
Input Format
The input consists of a single line containing a string. The string can include
alphabets, digits, spaces, and special characters.
Output Format
The program should output a modified string where lowercase characters appear
first, followed by uppercase characters.
The order of characters within each group (lowercase and uppercase) should
remain the same as in the original string.

Refer to the sample output for following format specifications.


Constraints
The length of the input string is at most 100 characters.
Sample Input Sample Output
Welcome to Java Training
elcome to ava rainingWJT
Sample Input Sample Output
Hi All, This is a Sample Output
i ll, his is a ample utput HATSO
Time Limit: - ms Memory Limit: - kb Code Size: - kb

Q2.
Problem Statement

Seetha, a math teacher, explained Matrix addition, subtraction, and multiplication


in her class. She assigned different tasks to her students.
She asked Ankit to add two matrices, Banu to subtract two matrices, and Janu to
multiply two matrices. Ankit, Banu, and Janu approached Karthick to complete
their task.

Karthick is ready to help all his friends with a single program. So he asked his
friends to give a square matrix only. Help Karthick write the program.
Input Format
The first line contains an integer N, representing the size of the square matrices.
The next N lines contain N space-separated integers, representing the elements of
the first matrix.
The next N lines contain N space-separated integers, representing the elements of
the second matrix.

Refer to the sample input for the formatting specifications.


Output Format
The output displays the result of addition, subtraction, and multiplication.

Refer to the sample output for the formatting specifications.


Constraints
The test cases will fall under the following constraints:
2 <= N <= 10
0 <= elements of matrices <= 100
square matrix only
Sample Input Sample Output
3
1 2 3
1 2 3
1 2 3
3 2 1
3 2 1
3 2 1
Matrix Addition:
4 4 4
4 4 4
4 4 4
Matrix Subtraction:
-2 0 2
-2 0 2
-2 0 2
Matrix Multiplication:
18 12 6
18 12 6
18 12 6
Time Limit: - ms Memory Limit: - kb Code Size: - kb

Q3.
Problem Statement
Write a program to insert an element at a specified position in the array and find
the duplicate values of the array of float values.
Input Format
The first line of the input consists of the integer value n, representing the total
number of elements.
The second line of the input consists of the n-float array elements.
The third input consists of an integer value that represents position
The fourth input is the float element to be inserted.
Output Format
The first line of the output prints the newly formed array, separated by a space.
Then print the duplicate elements on consecutive lines.

Note: There is an extra space at the end of the first line of output.
Refer to the sample output for the formatting specifications
Constraints
1<=n<=20
1<=elements<=100
Sample Input Sample Output
10
1.23 2.23 3.12 4.34 5.45 6.56 1.12 2.78 9.5 9.5
2
8.67
1.23 8.67 2.23 3.12 4.34 5.45 6.56 1.12 2.78 9.5 9.5
9.5
Sample Input Sample Output
10
11.23 22.23 31.12 14.34 15.45 16.56 11.12 12.78 91.5 91.5
5
8.67
11.23 22.23 31.12 14.34 8.67 15.45 16.56 11.12 12.78 91.5 91.5
91.5
Time Limit: - ms Memory Limit: - kb Code Size: - kb

Q4.
Problem statement

Create two classes a Box class and a Main class, create an object for the Box class
in the Main class, and calculate the volume of the box.
Input Format
The first line of input consists double value of the width, height, and depth
separated by space.
Output Format
The output displays the volume of the box.
If inputs <= 0, then print "Invalid".
Constraints
1=width, height, and depth <=100
Sample Input Sample Output
7.2 8.0 1.1
63.36
Sample Input Sample Output
-1.5 -8.5 -88.0
Invalid
Time Limit: - ms Memory Limit: - kb Code Size: - kb

Q5.
Write a program to display the result of the following expression: -x+y*z
Input Format
The input consists of three integers x, y, and z, separated by a space.
Output Format
If 'x', 'y', and 'z' are all positive values, the output displays the result of the
mathematical expression as an integer.
If any of 'x', 'y', or 'z' is not positive, the output displays "Invalid."

Refer to the sample output for the formatting specifications.


Constraints
0 < x, y, z <= 1000
Sample Input Sample Output
7 6 8
41
Sample Input Sample Output
-9 6 0
Invalid
Time Limit: - ms Memory Limit: - kb Code Size: - kb

Q6.
Problem Statement

Nila, who is new to programming, is eager to explore the world of coding. She
wishes to understand basic mathematical operations using programming.

Help Nila by creating a simple program that calculates the square, cube, and
square root of a given number.
Input Format
The input consists of an integer, n.
Output Format
The output should display in the following format:

The first line of output should displays the Square of 5 is: {Square value}.
The second line of output should displays Cube of 5 is:{Cube value}.
The third line of output should displays Square Root of 5 is:{Cube value} with two
decimal places.

Refer to the sample output for the formatting specifications.


Constraints
1 <= n <= 100.
Sample Input Sample Output
5
Square of 5 is: 25.0
Cube of 5 is: 125.0
Square Root of 5 is: 2.24
Sample Input Sample Output
7
Square of 7 is: 49.0
Cube of 7 is: 343.0
Square Root of 7 is: 2.65
Time Limit: - ms Memory Limit: - kb Code Size: - kb

Q7.
Write a program to calculate the area of a rectangle. The program should take the
length and breadth of the rectangle as input and calculate the area as a float.
However, it should also validate the input to ensure that both the length and
breadth are positive values.

Note: area of rectangle = l * b


Input Format
The input consists of two space-separated integers, 'l' and 'b', representing the
length and breadth of the rectangle.
Output Format
If both 'l' and 'b' are positive values, output displays a single line containing the
area of the rectangle in floating-point format.
If either 'l' or 'b' is not a positive value, the output displays "Invalid".

Refer to the sample output for the formatting specifications.


Constraints
The test cases will fall under the following constraints:

l >0 && b >0


1 <= l, b <= 109
Sample Input Sample Output
5 6
30.0
Sample Input Sample Output
-3 6
Invalid
Time Limit: - ms Memory Limit: - kb Code Size: - kb

Q8.
Problem Statement

In a triangle game show, participants are given the three angles of a triangle, and
they need to guess the type of triangle they form. Your task is to write a program
that takes the three angles as input and determines the type of triangle based on
the following rules:

 If the sum of the angles is equal to 180 degrees:If all three angles are equal, the
triangle is an equilateral triangle, and the participant wins Prize 3.
 If any one of the angles is a right angle (90 degrees), the triangle is a right-angled
triangle, and the participant wins Prize 2.
 Otherwise, the triangle is a regular triangle, and the participant wins Prize 1.
 If the sum of the angles is not equal to 180 degrees, the triangle is invalid, and the
participant wins no prize.
Input Format
The input consists of three integers, angle 1, angle 2, and angle 3, representing
the three angles of the triangle.
Output Format
The program will output a single line containing the type of triangle and the
corresponding prize. The possible outputs are:

 "Prize 3" for an equilateral triangle.


 "Prize 2" for a right-angled triangle.
 "Prize 1" for a regular triangle.
 "No prize" for an invalid triangle.

Refer to the sample output for format specifications.


Constraints
0 ≤ angle1, angle2, angle3 ≤ 180
The sum of angle 1, angle 2, and angle 3 is always 180.
Sample Input Sample Output
60
50
70
Prize 1
Sample Input Sample Output
60
60
70
No prize
Sample Input Sample Output
90
40
50
Prize 2
Sample Input Sample Output
60
60
60
Prize 3
Time Limit: - ms Memory Limit: - kb Code Size: - kb
Q9.
Valid Initial Configuration

The Nurikabe logical game (sometimes called Islands in the Stream) is a binary
determination puzzle. The puzzle is played on a typically rectangular grid of cells,
some of which contain numbers. You must decide for each cell if it is white or
black (by clicking on it) according to the following rules:
1. All of the black cells must be connected.
2. Each numbered cell must be part of a white island of connected white cells.
3. Each island must have the same number of white cells as the number of cells it
contains (including the numbered cell).
4. Two islands may not be connected.
5. There cannot be any 2x2 blocks of black cells.
6. Unnumbered cells start out grey and cycle through white and black when clicked.
Initially numbered cells are white in color.

Problem Statement:

Write a program to check whether the given board configuration is a valid initial
configuration. Below is a sample valid initial configuration.

Input Format
The first line of the input is an integer N that gives the number of rows and
columns of the grid.
The next N lines will have the board configuration of N*N cells. Assume that the
maximum number in a cell is 10. Grey-colored cells are represented by the integer
20 in the matrix representation of the input configuration.
Output Format
The output is "Yes" (without quotes) if the given configuration is a valid initial
configuration. Print "no" otherwise (without quotes).

Refer to sample input and output for formatting specifications.


Constraints
1<=N<=15
1<=number<=10
Sample Input Sample Output
5
20 20 1 20 3
20 20 20 20 20
20 20 20 20 20
20 20 20 20 20
6 20 3 20 20
Yes
Sample Input Sample Output
5
20 20 1 20 3
20 20 20 20 20
20 20 12 20 20
20 20 20 20 20
6 20 3 20 20
No
Time Limit: - ms Memory Limit: - kb Code Size: - kb

Q10.

Problem Statement

Akil is working on a program to take various types of user inputs and display them
in a formatted manner. He needs your help in completing the code.

Write a Java program that prompts the user for different types of inputs and
displays them back with appropriate labels.
Input Format
The first line of input consists of an integer.
The second line of input consists of a double.
The third line of input consists of boolean value, which is either true or false
The fourth line of input consists of a single character
The fifth line of input consists of a String input
Output Format
The output displays the entered values in the following format:

Integer value = <n1>


Double value = <n2>
Boolean value = <n3>
Char value = <c>
String value = <n4>

Refer to the sample output for the formatting specifications.


Constraints
1 ≤n1 <≤105.
0.1≤n2≤100.0
n3 is either true or false.
c is a single character.
The length of n4 is at most 100 characters.
Sample Input Sample Output
42
3.14
true
A
Hello, World!
Integer value = 42
Double value = 3.14
Boolean value = true
Char value = A
String value = Hello, World!
Sample Input Sample Output
123
7.5
false
x
Java Programming
Integer value = 123
Double value = 7.5
Boolean value = false
Char value = x
String value = Java Programming
Time Limit: - ms Memory Limit: - kb Code Size: - kb

Q11.
Problem Statement

The Nurikabe logical game (sometimes called Islands in the Stream) is a binary
determination puzzle. The puzzle is played on a typically rectangular grid of cells,
some of which contain numbers.

You must decide for each cell if it is white or black (by clicking on it) according to
the following rules:

 All of the black cells must be connected.


 Each numbered cell must be part of a white island of connected white cells.
 Each island must have the same number of white cells as the number it contains
(including the numbered cell).
 Two islands may not be connected.
 There cannot be any 2x2 blocks of black cells.
 Unnumbered cells start out grey and cycle through white and black when clicked.
Initially numbered cells are white in color.

Write a program to find the number of white cells in the final configuration of the
board based on the given a valid initial configuration.
Below figure is the sample value.

Input Format
The first line of the input is an integer N that gives the number of rows and
columns in the grid.
The next N lines will have a valid initial board configuration with N*N cells. Assume
that the maximum number in a cell can be 10. Grey-colored cells are represented
by the integer 20 in the matrix representation of the input configuration.
Output Format
The program prints an integer representing the number of white cells in the final
configuration of the board.

Refer to the sample input and output for format specifications.


Constraints
2 <= N <= 20.
The grid cells contain integers less than 21.
Sample Input Sample Output
5
20 20 1 20 3
20 20 20 20 20
20 20 20 20 20
20 20 20 20 20
6 20 3 20 20
13
Sample Input Sample Output
5
20 20 20 20 20
3 20 20 6 20
20 20 20 20 20
20 2 20 20 1
20 20 20 20 20
12
Time Limit: - ms Memory Limit: - kb Code Size: - kb

Q12.
Problem Statement

Write a program to find the normal of a matrix.


Input Format
The first line of the input consists of an integer value of N representing the number
of rows and columns.
The remaining line of the input consists of matrix elements 'E'.
Output Format
The output should display the normal of the given matrix.

Refer to the sample output for the formatting specifications.


Constraints
In this scenario, the test cases fall under the following constraints:
0 ≤ N ≤ 10
0 ≤ E ≤ 10
Sample Input Sample Output
5
1 1 1 1 1
2 2 2 2 2
3 3 3 3 3
4 4 4 4 4
5 5 5 5 5
16
Sample Input Sample Output
4
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
38
Time Limit: - ms Memory Limit: - kb Code Size: - kb

Q13.
Problem Statement

Given an array of numbers. Give an algorithm for finding the first element in the
array which is repeated.
Input Format
The first line of the input consists of an integer representing the size of array 'n'.
The second line of the input consists of n elements representing the array
elements 'e' separated by space.
Output Format
The output should display the first repeating element in the array as
"The first repeating element is <<element>>" or "There are no repeating elements"

Refer to the sample output for the formatting specifications.


Constraints
In this scenario, the test cases fall under the following constraints:
1 ≤ n ≤ 10
1 ≤ e ≤ 100
Sample Input Sample Output
7
10 5 3 5 3 4 6
The first repeating element is 5
Sample Input Sample Output
5
1 5 6 8 7
There are no repeating elements
Sample Input Sample Output
8
5 2 4 6 7 2 4 5
The first repeating element is 5
Time Limit: - ms Memory Limit: - kb Code Size: - kb

Q14.
Problem Statement
Given an array of elements. Find two elements in the array such that their sum is
equal to the given element K.
Input Format
The first line contains an integer n representing the length of the array.
The second line contains n space-separated integers representing the elements e
of the array.
The third line contains an integer K representing the target sum.
Output Format
The output should display whether the array has a pair of elements with the given
sum as
"Array has two elements with given sum <<sum>>" or "Array doesn't have two
elements with given sum <<sum>>"

Refer to the sample output for the formatting specifications.


Constraints
In this scenario, the test cases fall under the following constraints:
1 ≤ n ≤ 10
1 ≤ e ≤ 100
1 ≤ k ≤ 100
Sample Input Sample Output
6
1 4 45 6 10 8
16
Array has two elements with given sum 16
Sample Input Sample Output
6
1 4 45 6 10 8
60
Array doesn't have two elements with given sum 60
Time Limit: - ms Memory Limit: - kb Code Size: - kb

Q15.
Problem Statement

Riya is a student studying in a school. Her mathematics teacher has given her an
interesting assignment. The assignment is to find the sum of the diagonal elements
of a square matrix. Riya is not familiar with programming and seeks your help to
complete the task. Can you write a program to help Riya find the sum of the
diagonal elements?

Note: Only a square matrix.


Input Format
The first line of input consists of the number of rows and columns separated by a
space (n,m).
The remaining input lines represent the elements of the array.
Output Format
The output should display the sum of diagonal elements.
Refer to the sample output for format specifications.
Constraints
In this scenario, the test cases fall under the following constraints:
0 ≤ n ≤ 10
0 ≤ m ≤ 10
0 ≤ e ≤ 100
Sample Input Sample Output
3 3
1 2 3
4 5 6
7 8 9
15
Sample Input Sample Output
4 4
12 23 45 56
78 89 98 87
65 54 32 21
14 25 36 58
191
Time Limit: - ms Memory Limit: - kb Code Size: - kb

Q16.
Problem Statement

Ashok is learning about bitwise operations in Java. He wants to write a program to


perform a bitwise OR operation on two given integers.

Write a program that takes two integers as input and performs a bitwise OR
operation on them.
Input Format
The input consists of two integers, number 1 and number 2, separated by a space.
Output Format
The output displays the result after performing the bitwise operation.

Refer to the sample output for the formatting specifications.


Constraints
The test cases will fall under the following constraints:
-103 <= number 1, number 2 <= 103
Sample Input Sample Output
78 90
94
Sample Input Sample Output
5 7
7
Time Limit: - ms Memory Limit: - kb Code Size: - kb
Q17.
Problem Statement

Nella is an eight-year-old princess who will inherit the kingdom of Castlehaven. It


is her birthday today, and her dad, the King of Castlehaven, has arranged for a
grand party. Nella loves colorful balloons, so her dad planned to decorate the
entire palace with balloons of the colors that she loved. So he asked her about her
color preferences. As the sophisticated princess that Nella is, she likes only two
colors: amber and brass. Her dad bought n balloons, each of which was either
amber or brass in color.

You are provided this information in a string consisting only of the characters 'a'
and 'b, where 'a' denotes that the balloon is amber and 'b' denotes that it is brass
colored. When Nella saw the balloons, she was furious with anger, as she wanted
all the balloons to be the same color. In her rage, she painted some of the balloons
the opposite color (i.e., she painted some amber ones brass and vice versa) to
make all balloons appear to be the same color.

It took her a lot of time to do this, but you can probably show her the right way of
doing so, thereby teaching her a lesson to remain calm in difficult situations by
finding out the minimum number of balloons needed to be painted in order to
make all of them the same color.

Example,
Input:
aabbb
Output:
2

Explanation:
The given input string has 2 'a's and 3 'b's. Therefore, the output will be the
minimum count of the two, which is 2.
Input Format
The first and only line of input contains a string.
Output Format
The output is a single line containing an integer representing the minimum number
of flips required.

Refer to sample output for formatting specifications.


Constraints
contains only a and b
Sample Input Sample Output
aabbb
2
Sample Input Sample Output
baaba
2
Time Limit: - ms Memory Limit: - kb Code Size: - kb

Q18.
Problem Statement:

Rohit has an array of integers, and he wants to find the missing number in the
array. The array initially contains all the numbers from 1 to num+1, but one
number is missing. Rohit needs to determine and print the missing number.

Help him write a Java program to print the missing number.


Input Format
The first line contains an integer, num, representing the number of elements in
the array.
The second line contains num space-separated integers, representing the elements
of the array.
Output Format
The program prints an integer, representing the missing number in the array.

Refer to the sample output for formatting specifications.


Constraints
1<=num<=100.
1<=elements<=100.
Sample Input Sample Output
5
6 4 3 2 1
5
Sample Input Sample Output
15
4 6 5 7 3 1 2 9 8 10 12 15 14 13 16
11
Time Limit: - ms Memory Limit: - kb Code Size: - kb

Q19.
Problem Statement

Bob is learning about prime numbers and wants to create a simple program to
check whether a given number is prime or not. He asked for your help in writing
this program.

Write a program that takes an integer n as input and determines whether it is a


prime number or not.
Input Format
The input consists of an integer value.
Output Format
If the given integer is 0 or 1, print "0 is not a prime number" or "1 is not a prime
number" respectively.
If the given integer is a prime number, print "n is a prime number".
If the given integer is not a prime number, print "n is not a prime number".

Refer to the sample output for the formatting specifications.


Constraints
0≤n≤103.
Sample Input Sample Output
7
7 is prime number
Sample Input Sample Output
9
9 is not prime number
Time Limit: - ms Memory Limit: - kb Code Size: - kb

Q20.
Problem Statement

Ragav, a detail-oriented person, wants to analyze his expenses across four main
categories: Branding, Travel, Food, and Logistics. He needs a program to calculate
the total expenses and the percentage of spending in each category relative to the
total amount spent.
Input Format
The first line of input is a double, which represents the expense of Branding.
The second line of input is a double, which represents the expense of Travel.
The third line of input is a double, which represents the expense of Food.
The fourth line of input is a double, which represents the expense of Logistics.
Output Format
The output displays the following lines:
"Total expenses : Rs.XX".
"Branding expenses percentage : YY%"..
"Travel expenses percentage : ZZ%".
"Food expenses percentage : WW%".
"Logistics expenses percentage : VV%".

where XX, YY, ZZ, WW, VV, rounded to two decimal places

Refer to the sample output for the formatting specifications.


Constraints
1.0 <= Branding, Travel, Food, Logistics <= 107.0
Sample Input Sample Output
20000.0
40000.0
15000.0
25000.0
Total expenses : Rs.100000.00
Branding expenses percentage : 20.00%
Travel expenses percentage : 40.00%
Food expenses percentage : 15.00%
Logistics expenses percentage : 25.00%
Time Limit: 10 ms Memory Limit: 256 kb Code Size: 1024 kb

Answer Key & Solution


Section 1 - CODING

Q1Test CaseInputOutput
HAI How Are You?
ow re ou?HAIHAY

Weightage - 10InputOutput
a Long Time Ago There Was a Hare Who Wouldnt Stop Teasing a Tortoise For
His Slowness. Im the fastest runner in the woods and you are the slowest
one! We should compete! He jeered.the next day the Tortoise And The Hare
Stood At the start, ready for the race. One, two, three, go, said the hare
and they started running.
a ong ime go here as a are ho ouldnt top easing a ortoise or is lowness. m
the fastest runner in the woods and you are the slowest one! e should
compete! e jeered.the next day the ortoise nd he are tood t the start,
ready for the race. ne, two, three, go, said the hare and they started
running.LTATWHWWSTTFHSIWHTATHSAO

Weightage - 15InputOutput
Today, more than ever, marketers must understand the importance of data. It
drives all decisions around who And How To Market A Product or service, and
in the Business 4.0 era, marketers are provided With New Innovative Tools
That Allow Them To Analyze And Act Upon data in ways that were previously
unimaginable
oday, more than ever, marketers must understand the importance of data. t
drives all decisions around who nd ow o arket roduct or service, and in
the usiness 4.0 era, marketers are provided ith ew nnovative ools hat llow
hem o nalyze nd ct pon data in ways that were previously
unimaginableTIAHTMAPBWNITTATTAAAU

Weightage - 15InputOutput
Reaching consumers via Artificial Intelligence and Machine Learning
eaching consumers via rtificial ntelligence and achine earningRAIML

Weightage - 25InputOutput
With non-interoperable legacy enterprise systems it is difficult to
capture, process, analyze, archive and exchange data in an efficient and
cost-effective manner. Manual transfer of different types of clinical data
e.g. demographic, safety and visit is cumbersome and prone to errors when
the exchange involves numerous Stakeholders Within The Clinical trial
ecosystem. Furthermore, merger and acquisition activities and intensive re-
engineering has increased the complexity of operations with multiple
versions of data management PROCESSES AND DISPARATE TECHNOLOGIES used
across in-house, outsourcing, and offshore operational models. Data
confidence is a constant battle and the companies need to ascertain that
the data collected is standardized and trustworthy.
ith non-interoperable legacy enterprise systems it is difficult to capture,
process, analyze, archive and exchange data in an efficient and cost-
effective manner. anual transfer of different types of clinical data e.g.
demographic, safety and visit is cumbersome and prone to errors when the
exchange involves numerous takeholders ithin he linical trial ecosystem.
urthermore, merger and acquisition activities and intensive re-engineering
has increased the complexity of operations with multiple versions of data
management used across in-house, outsourcing, and offshore operational
models. ata confidence is a constant battle and the companies need to
ascertain that the data collected is standardized and
trustworthy.WMSWTCFPROCESSESANDDISPARATETECHNOLOGIESD

Weightage - 25InputOutput
AlgorithmDesign
lgorithmesignAD

Weightage - 10Sample InputSample Output


Welcome to Java Training
elcome to ava rainingWJT

Sample InputSample Output


Hi All, This is a Sample Output
i ll, his is a ample utput HATSO

Solution
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner input =new Scanner(System.in);
String str = input.nextLine();
String uppercase = "";
String lowercase = "";
for(int i = 0; i < str.length(); i++) {
char ch = str.charAt(i);

if(Character.isUpperCase(ch)) {
uppercase += ch;
}
else {
lowercase += ch;
}
}
String output = lowercase + uppercase;
System.out.println(output);
}
}

Q2Test CaseInputOutput
2
2 2
2 2
2 2
2 2
Matrix Addition:
4 4
4 4
Matrix Subtraction:
0 0
0 0
Matrix Multiplication:
8 8
8 8

Weightage - 10InputOutput
2
0 0
0 0
2 2
2 2
Matrix Addition:
2 2
2 2
Matrix Subtraction:
-2 -2
-2 -2
Matrix Multiplication:
0 0
0 0

Weightage - 15InputOutput
3
100 3 59
32 3 0
20 32 98
1 34 53
43 43 22
55 34 42
Matrix Addition:
101 37 112
75 46 22
75 66 140
Matrix Subtraction:
99 -31 6
-11 -40 -22
-35 -2 56
Matrix Multiplication:
3474 5535 7844
161 1217 1762
6786 5388 5880

Weightage - 25InputOutput
5
1 1 1 1 1
2 2 2 2 2
3 3 3 3 3
4 4 4 4 4
5 5 5 5 5
10 10 10 10 10
20 20 20 20 20
30 30 30 30 30
40 40 40 40 40
50 50 50 50 50
Matrix Addition:
11 11 11 11 11
22 22 22 22 22
33 33 33 33 33
44 44 44 44 44
55 55 55 55 55
Matrix Subtraction:
-9 -9 -9 -9 -9
-18 -18 -18 -18 -18
-27 -27 -27 -27 -27
-36 -36 -36 -36 -36
-45 -45 -45 -45 -45
Matrix Multiplication:
150 150 150 150 150
300 300 300 300 300
450 450 450 450 450
600 600 600 600 600
750 750 750 750 750

Weightage - 25InputOutput
2
8 1
2 8
2 8
1 9
Matrix Addition:
10 9
3 17
Matrix Subtraction:
6 -7
1 -1
Matrix Multiplication:
17 73
12 88

Weightage - 10InputOutput
3
1 2 3
4 5 6
7 8 9
4 5 6
2 6 8
9 4 2
Matrix Addition:
5 7 9
6 11 14
16 12 11
Matrix Subtraction:
-3 -3 -3
2 -1 -2
-2 4 7
Matrix Multiplication:
35 29 28
80 74 76
125 119 124

Weightage - 15Sample InputSample Output


3
1 2 3
1 2 3
1 2 3
3 2 1
3 2 1
3 2 1
Matrix Addition:
4 4 4
4 4 4
4 4 4
Matrix Subtraction:
-2 0 2
-2 0 2
-2 0 2
Matrix Multiplication:
18 12 6
18 12 6
18 12 6

Solution
import java.util.Scanner;

public class Main {


public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();

int[][] matrix1 = new int[N][N];


for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
matrix1[i][j] = sc.nextInt();
}
}

int[][] matrix2 = new int[N][N];


for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
matrix2[i][j] = sc.nextInt();
}
}

int[][] addition = new int[N][N];


int[][] subtraction = new int[N][N];
int[][] multiplication = new int[N][N];

for (int i = 0; i < N; i++) {


for (int j = 0; j < N; j++) {
addition[i][j] = matrix1[i][j] + matrix2[i][j];
subtraction[i][j] = matrix1[i][j] - matrix2[i][j];
multiplication[i][j] = 0;
for (int k = 0; k < N; k++) {
multiplication[i][j] += matrix1[i][k] * matrix2[k][j];
}
}
}

System.out.println("Matrix Addition:");
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
System.out.print(addition[i][j] + " ");
}
System.out.println();
}

System.out.println("Matrix Subtraction:");
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
System.out.print(subtraction[i][j] + " ");
}
System.out.println();
}

System.out.println("Matrix Multiplication:");
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
System.out.print(multiplication[i][j] + " ");
}
System.out.println();
}
}
}

Q3Test CaseInputOutput
5
11.1 12.2 13.3 24.4 25.5
2
8.4
11.1 8.4 12.2 13.3 24.4 25.5

Weightage - 10InputOutput
12
12.23 25.23 44.32 85.23 76.45 95.45 20.45 22.45 4.24 7.26 20.23 99.32
5
88.23
12.23 25.23 44.32 85.23 88.23 76.45 95.45 20.45 22.45 4.24 7.26 20.23 99.32

Weightage - 15InputOutput
15
12.3 45.6 78.9 98.7 65.4 32.1 12.3 45.6 78.9 14.7 24.8 36.9 15.9 35.7 24.8
10
88.8
12.3 45.6 78.9 98.7 65.4 32.1 12.3 45.6 78.9 88.8 14.7 24.8 36.9 15.9 35.7
24.8
12.3
45.6
78.9
24.8

Weightage - 25InputOutput
20
1.0 2.0 3.0 40.0 50.0 6.0 7.0 8.0 9.0 10.0 11.0 12.0 13.0 14.0 15.0 16.0
17.0 18.0 19.0 18.0
20
22.0
1.0 2.0 3.0 40.0 50.0 6.0 7.0 8.0 9.0 10.0 11.0 12.0 13.0 14.0 15.0 16.0
17.0 18.0 19.0 22.0 18.0
18.0

Weightage - 25InputOutput
7
11.1 12.2 13.3 24.4 25.5 34.4 45.5
2
8.4
11.1 8.4 12.2 13.3 24.4 25.5 34.4 45.5

Weightage - 10InputOutput
10
12.1 12.2 13.3 24.4 25.5 25.4 25.4 76.3 89.0 44.5
7
5.6
12.1 12.2 13.3 24.4 25.5 25.4 5.6 25.4 76.3 89.0 44.5
25.4

Weightage - 15Sample InputSample Output


10
1.23 2.23 3.12 4.34 5.45 6.56 1.12 2.78 9.5 9.5
2
8.67
1.23 8.67 2.23 3.12 4.34 5.45 6.56 1.12 2.78 9.5 9.5
9.5

Sample InputSample Output


10
11.23 22.23 31.12 14.34 15.45 16.56 11.12 12.78 91.5 91.5
5
8.67
11.23 22.23 31.12 14.34 8.67 15.45 16.56 11.12 12.78 91.5 91.5
91.5

Solution
import java.io.*;
import java.util.*;
class main {
public static void main(String [] args) {
int i,j,n,pos;
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
double ele;
double arr[] = new double[n+1];
for(i=0;i<n;i++) {
arr[i] = sc.nextDouble();
}
pos = sc.nextInt();
ele = sc.nextDouble();
n++;
for (i = n-1; i >= pos; i--) {
arr[i] = arr[i - 1];
}
arr[pos - 1] = ele;
for(i=0;i<n;i++) {
System.out.print(arr[i]+" ");
}
System.out.println();
for(i=0;i<n;i++) {
for(j=i+1;j<n;j++) {
if(arr[i] == arr[j]) {
System.out.println(arr[j]);
}
}
}
}
}

Q4Test CaseInputOutput
2.2 1.1 3
7.26

Weightage - 10InputOutput
3 2 4
24.00

Weightage - 10InputOutput
3 4 5
60.00

Weightage - 15InputOutput
12.1 20.2 17.4
4252.91

Weightage - 25InputOutput
-1.0 1.2 1.4
Invalid

Weightage - 15InputOutput
99.2 98.2 100.2
976092.29

Weightage - 25Sample InputSample Output


7.2 8.0 1.1
63.36
Sample InputSample Output
-1.5 -8.5 -88.0
Invalid

Solution
import java.util.Scanner;
class Box {
double width;
double height;
double depth;

}
class Main {
public static void main(String args[]) {
Box mybox = new Box();
double vol;
Scanner sc=new Scanner(System.in);
mybox.width=sc.nextDouble() ;
mybox.height=sc.nextDouble() ;
mybox.depth=sc.nextDouble() ;
if(mybox.width>0 && mybox.height>0 && mybox.depth>0){
vol = mybox.width * mybox.height * mybox.depth;
System.out.format("%.2f",vol);
}else{
System.out.print("Invalid");
}
}
}

Q5Test CaseInputOutput
12 14 22
296

Weightage - 15InputOutput
0 8 7
Invalid

Weightage - 10InputOutput
6 8 12
90

Weightage - 15InputOutput
23 51 34
1711

Weightage - 25InputOutput
0 34 0
Invalid
Weightage - 10InputOutput
678 546 897
489084

Weightage - 25Sample InputSample Output


7 6 8
41

Sample InputSample Output


-9 6 0
Invalid

Solution
import java.util.Scanner;
class Main{
public static void main(String[] args) {
int x,y,z;
Scanner in =new Scanner(System.in);
x=in.nextInt();
y=in.nextInt();
z=in.nextInt();
if(x>0&&y>0&&z>0){
System.out.println(-x + y * z);
}
else{
System.out.println("Invalid");
}
}
}

Q6Test CaseInputOutput
6
Square of 6 is: 36.0
Cube of 6 is: 216.0
Square Root of 6 is: 2.45

Weightage - 10InputOutput
3
Square of 3 is: 9.0
Cube of 3 is: 27.0
Square Root of 3 is: 1.73

Weightage - 10InputOutput
8
Square of 8 is: 64.0
Cube of 8 is: 512.0
Square Root of 8 is: 2.83
Weightage - 15InputOutput
12
Square of 12 is: 144.0
Cube of 12 is: 1728.0
Square Root of 12 is: 3.46

Weightage - 15InputOutput
10
Square of 10 is: 100.0
Cube of 10 is: 1000.0
Square Root of 10 is: 3.16

Weightage - 25InputOutput
100
Square of 100 is: 10000.0
Cube of 100 is: 1000000.0
Square Root of 100 is: 10.00

Weightage - 25Sample InputSample Output


5
Square of 5 is: 25.0
Cube of 5 is: 125.0
Square Root of 5 is: 2.24

Sample InputSample Output


7
Square of 7 is: 49.0
Cube of 7 is: 343.0
Square Root of 7 is: 2.65

Solution
import java.util.Scanner;

class j5 {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int num;
num = sc.nextInt();

System.out.println("Square of " + num + " is: " + Math.pow(num, 2));


System.out.println("Cube of " + num + " is: " + Math.pow(num, 3));

// Display square root with two decimal places


System.out.printf("Square Root of %d is: %.2f%n", num, Math.sqrt(num));
}
}
Q7Test CaseInputOutput
-9 -8
Invalid

Weightage - 30InputOutput
50 89
4450.0

Weightage - 10InputOutput
6 -8
Invalid

Weightage - 20InputOutput
11 22
242.0

Weightage - 10InputOutput
55 77
4235.0

Weightage - 10InputOutput
209 309
64581.0

Weightage - 10InputOutput
-9 -7
Invalid

Weightage - 10Sample InputSample Output


5 6
30.0

Sample InputSample Output


-3 6
Invalid

Solution
import java.util.Scanner;
class Area{
public static void main(String args[]){
int l,b;
float ar;
Scanner sc=new Scanner(System.in);
l=sc.nextInt();
b=sc.nextInt();
if(l>0&&b>0){
ar=l*b;
System.out.println(ar);
}
else
{
System.out.println("Invalid");
}

}
}

Q8Test CaseInputOutput
60
60
60
Prize 3

Weightage - 10InputOutput
90
45
45
Prize 2

Weightage - 10InputOutput
90
50
40
Prize 2

Weightage - 15InputOutput
80
60
40
Prize 1

Weightage - 15InputOutput
50
50
80
Prize 1

Weightage - 25InputOutput
80
80
90
No prize

Weightage - 25Sample InputSample Output


60
50
70
Prize 1

Sample InputSample Output


60
60
70
No prize

Sample InputSample Output


90
40
50
Prize 2

Sample InputSample Output


60
60
60
Prize 3

Solution
import java.util.*;
import java.io.*;
class Trianglegame {
public static void main(String [] args) {
int angle1,angle2,angle3;
Scanner sc = new Scanner(System.in);
angle1 = sc.nextInt();
angle2 = sc.nextInt();
angle3 = sc.nextInt();
if((angle1+angle2+angle3) == 180) {
if(angle1 == angle2 && angle2 == angle3 && angle1 == angle3) {
System.out.println("Prize 3");
}
else if(angle1 == 90 || angle2 ==90 || angle3 == 90) {
System.out.println("Prize 2");
}
else {
System.out.println("Prize 1");
}

}
else {
System.out.println("No prize");
}
}
}

Q9Test CaseInputOutput

5
20 20 1 20 5
20 20 20 20 20
20 20 20 20 20
20 20 20 20 20
6 20 20 2 20
Yes

Weightage - 10InputOutput
9
5 3 1 20 3 20 20 20 1
8 20 6 20 7 20 1 8 20
20 20 18 20 20 20 2 1 20
20 20 17 20 20 2 20 20 1
6 20 3 20 20 20 20 1 20
10 8 20 20 2 20 5 20 3
20 20 1 20 20 1 20 2 20
9 20 20 8 20 20 20 20 20
20 1 20 20 5 20 20 20 2
No

Weightage - 15InputOutput
12
20 20 1 20 3 20 20 20 1 20 1 20
20 20 20 20 20 20 1 20 20 20 20 1
20 20 20 20 20 20 2 1 20 20 20 20
20 20 20 20 20 2 20 20 1 1 20 20
6 20 3 20 20 20 20 1 20 1 20 20
20 20 20 20 2 20 20 20 3 20 20 20
20 20 1 20 20 1 20 2 20 1 20 20
20 20 20 20 20 20 20 20 20 1 20 20
20 1 20 20 5 20 20 20 2 20 20 20
20 20 20 1 20 20 20 20 1 20 20 20
20 1 20 20 5 20 20 20 4 20 20 20
20 20 20 20 20 1 20 20 1 1 1 20 20
Yes

Weightage - 25InputOutput
12
20 20 1 20 3 20 20 20 1 20 1 20
20 20 20 20 20 20 1 20 20 20 20 1
20 20 20 20 20 20 2 1 20 20 20 20
20 20 20 20 20 2 20 20 1 1 20 20
6 20 3 20 20 20 20 1 20 1 20 20
20 20 20 20 2 20 20 20 3 20 20 20
20 20 1 20 20 1 20 2 20 1 20 20
20 20 20 20 20 20 19 20 20 1 20 20
20 1 20 20 5 20 20 20 2 20 20 18
20 20 20 1 20 20 20 20 1 20 20 20
20 1 20 20 5 20 20 20 4 20 20 20
20 20 20 20 20 1 20 20 1 1 1 20 17
No

Weightage - 25InputOutput
5
20 20 1 20 3
20 20 20 20 20
20 20 20 20 20
20 20 20 20 20
6 20 3 4 20
Yes

Weightage - 10InputOutput
9
5 3 1 20 3 20 20 20 1
8 20 6 20 7 20 1 8 8
20 20 18 20 20 20 2 1 7
20 20 17 20 20 2 20 20 1
6 20 3 20 20 20 20 1 20
10 8 20 20 2 20 5 20 3
20 20 1 20 20 1 20 2 20
9 20 20 8 20 20 20 20 9
20 1 20 20 5 20 20 20 2
No

Weightage - 15Sample InputSample Output


5
20 20 1 20 3
20 20 20 20 20
20 20 20 20 20
20 20 20 20 20
6 20 3 20 20
Yes

Sample InputSample Output


5
20 20 1 20 3
20 20 20 20 20
20 20 12 20 20
20 20 20 20 20
6 20 3 20 20
No

Solution
import java.io.*;
import java.util.*;
class validInitialConfiguration {
public static void main(String [] args) {
int i,j,n,s=1;
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
int a[][] = new int[n][n];
for(i=0;i<n;i++) {
for(j=0;j<n;j++) {
a[i][j] = sc.nextInt();
}
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if((a[i][j]!=20)&&(a[i][j]>10)) {
s=0;
}
}
}
if(s == 0) {
System.out.println("No");
}
else {
System.out.println("Yes");
}

}
}

Q10Test CaseInputOutput
999
99.99
true
Z
Medium Challenge
Integer value = 999
Double value = 99.99
Boolean value = true
Char value = Z
String value = Medium Challenge
Weightage - 10InputOutput
123
45.67
true
!
Advanced Test
Integer value = 123
Double value = 45.67
Boolean value = true
Char value = !
String value = Advanced Test

Weightage - 15InputOutput
987
123.456
false
%
Challenging Input
Integer value = 987
Double value = 123.456
Boolean value = false
Char value = %
String value = Challenging Input

Weightage - 15InputOutput
7
1.5
false
X
Easy Example
Integer value = 7
Double value = 1.5
Boolean value = false
Char value = X
String value = Easy Example

Weightage - 10InputOutput
9999
99.99
true
Y
Quick Test
Integer value = 9999
Double value = 99.99
Boolean value = true
Char value = Y
String value = Quick Test

Weightage - 25InputOutput
500
123.45
false
^
Complex String
Integer value = 500
Double value = 123.45
Boolean value = false
Char value = ^
String value = Complex String

Weightage - 25Sample InputSample Output


42
3.14
true
A
Hello, World!
Integer value = 42
Double value = 3.14
Boolean value = true
Char value = A
String value = Hello, World!

Sample InputSample Output


123
7.5
false
x
Java Programming
Integer value = 123
Double value = 7.5
Boolean value = false
Char value = x
String value = Java Programming

Solution
import java.util.Scanner;

class Main {

public static void main(String[] args) {


Scanner s = new Scanner(System.in);

int n1 = s.nextInt();
double n2 = s.nextDouble();
boolean n3 = s.nextBoolean();
s.nextLine();
char c = s.nextLine().charAt(0);
String n4 = s.nextLine();

System.out.println("Integer value = " + n1 + "\nDouble value = " + n2 + "\


nBoolean value = " + n3 + "\nChar value = " + c + "\nString value = " + n4);

Q11Test CaseInputOutput
6
20 20 20 20 20 20
3 20 20 6 20 1
20 20 20 20 20 20
20 2 20 20 1 1
20 20 20 20 20 1
20 20 1 20 1 20
17

Weightage - 10InputOutput
9
20 5 20 20 3 20 20 20 20
20 20 8 20 20 20 20 5 20
20 20 20 20 20 20 2 20 20
20 20 20 20 20 20 20 20 20
20 20 20 20 20 20 20 20 20
20 20 20 20 20 20 20 20 20
20 20 3 20 20 20 20 20 20
20 3 20 20 20 20 3 20 20
20 20 20 20 1 20 20 6 20
39

Weightage - 15InputOutput
9
20 5 20 20 3 20 20 20 6
20 20 8 20 20 8 20 5 20
20 20 20 20 20 20 2 20 20
20 20 20 20 4 20 20 20 20
1 1 20 20 20 20 20 20 20
20 20 1 20 20 20 20 20 20
4 20 3 20 20 20 2 20 20
20 3 20 20 20 20 3 20 20
20 20 20 20 1 20 20 6 20
66

Weightage - 15InputOutput
12
20 5 20 20 3 20 20 20 6 20 1 20
20 20 8 20 20 8 20 5 20 1 20 1
20 20 20 20 20 20 2 20 20 20 20 1
20 20 20 20 4 20 20 20 20 20 1 20
1 1 20 20 20 20 20 20 20 1 20 20
20 20 1 20 20 20 20 20 20 20 20 20
4 20 3 20 20 20 2 20 20 20 1 1
20 3 20 20 20 20 3 20 20 1 1 1
20 20 20 20 1 20 20 6 20 20 2 20
20 20 20 20 1 1 1 1 20 20 20 2
1 1 1 1 1 1 1 1 1 1 1 1
20 20 20 20 1 20 20 20 20 1 20 1
100

Weightage - 25InputOutput
12
20 5 20 20 3 20 20 20 6 20 1 20
1 20 8 20 20 8 20 5 20 1 20 1
20 20 20 20 20 20 2 20 20 20 20 1
2 1 1 20 4 20 20 20 20 20 1 20
1 1 20 1 20 20 20 20 20 1 20 20
20 20 1 20 20 20 20 20 20 20 20 20
4 20 3 2 20 20 2 20 20 20 1 1
20 3 20 20 20 20 3 20 20 1 1 1
20 20 20 20 1 20 20 6 20 20 2 20
20 20 20 20 1 1 1 1 20 20 20 2
1 1 1 1 1 1 1 1 1 1 1 1
20 20 20 20 1 20 20 20 20 1 20 1
108

Weightage - 25InputOutput
4
0 2 0 0
2 0 0 1
0 1 0 0
0 0 2 0
8

Weightage - 10Sample InputSample Output


5
20 20 1 20 3
20 20 20 20 20
20 20 20 20 20
20 20 20 20 20
6 20 3 20 20
13

Sample InputSample Output


5
20 20 20 20 20
3 20 20 6 20
20 20 20 20 20
20 2 20 20 1
20 20 20 20 20
12

Solution
import java.io.*;
import java.util.*;
class numberofWhiteCells {
public static void main(String [] args) {
int i,j,n,count=0;
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
int a[][] = new int[n][n];
for(i=0;i<n;i++) {
for(j=0;j<n;j++) {
a[i][j] = sc.nextInt();
if(a[i][j] < 11) {
count += a[i][j];
}
}
}
System.out.println(count);
}
}

Q12Test CaseInputOutput
4
1 1 1 1 1
2 2 2 2 2
3 3 3 3 3
4 4 4 4 4
9

Weightage - 25InputOutput
4
1 2 3 4
5 6 7 8
9 10 11 12
17 18 19 20
44

Weightage - 25InputOutput
3
1 2 3
4 5 6
7 8 9
16

Weightage - 15InputOutput
2
1 2
1 2
3

Weightage - 10InputOutput
4
2 4 6 7
2 4 2 5
2 6 8 5
3 5 6 4
19

Weightage - 15InputOutput
3
3 56 3
23 5 2
6 43 2
74

Weightage - 10Sample InputSample Output


5
1 1 1 1 1
2 2 2 2 2
3 3 3 3 3
4 4 4 4 4
5 5 5 5 5
16

Sample InputSample Output


4
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
38

Solution
import java.util.Scanner;
class normal {
static int MAX = 100;
static int findNormal(int mat[][], int n)
{
int sum = 0;
for (int i=0; i<n; i++)
for (int j=0; j<n; j++)
sum += mat[i][j]*mat[i][j];
return (int)Math.sqrt(sum);
}

public static void main (String[] args) {


int i,j,n;
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
int [][] mat = new int[n][n];
for(i=0;i<n;i++) {
for(j=0;j<n;j++) {
mat[i][j] = sc.nextInt();
}
}
System.out.println (findNormal(mat, n));
}
}
import java.util.Scanner;

class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n, sum = 0;

// System.out.print("Enter the size of the matrix: ");


n = sc.nextInt();

int[][] mat = new int[n][n];


// System.out.println("Enter the elements of the matrix:");
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
mat[i][j] = sc.nextInt();
sum += mat[i][j] * mat[i][j];
}
}

int norm = (int) Math.sqrt(sum);


System.out.println(norm);
}
}

Q13Test CaseInputOutput
7
10 5 3 5 3 4 6
The first repeating element is 5

Weightage - 10InputOutput
5
8 4 6 2 3
There are no repeating elements

Weightage - 15InputOutput
8
8 2 4 6 7 2 4 8
The first repeating element is 8

Weightage - 25InputOutput
10
4 2 4 6 8 2 1 4 5 6
The first repeating element is 4

Weightage - 25InputOutput
5
1 56 34 23 59
There are no repeating elements

Weightage - 15InputOutput
7
23 45 23 78 90 23 67
The first repeating element is 23

Weightage - 10Sample InputSample Output


7
10 5 3 5 3 4 6
The first repeating element is 5

Sample InputSample Output


5
1 5 6 8 7
There are no repeating elements

Sample InputSample Output


8
5 2 4 6 7 2 4 5
The first repeating element is 5

Solution
import java.util.Scanner;

class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = sc.nextInt();
}
int min = -1;
for (int i = 0; i < arr.length; i++) {
for (int j = i + 1; j < arr.length; j++) {
if (arr[i] == arr[j]) {
min = i;
break;
}
}
if (min != -1) {
break;
}
}
if (min != -1)
System.out.println("The first repeating element is " + arr[min]);
else
System.out.println("There are no repeating elements");
}
}

Q14Test CaseInputOutput
8
12 35 74 96 20 2 6 8
94
Array has two elements with given sum 94

Weightage - 10InputOutput
8
12 35 74 96 20 2 6 8
99
Array doesn't have two elements with given sum 99

Weightage - 15InputOutput
10
12 23 45 56 78 89 14 25 36 85
81
Array has two elements with given sum 81

Weightage - 25InputOutput
10
12 23 45 56 78 89 14 25 36 85
100
Array doesn't have two elements with given sum 100

Weightage - 25InputOutput
6
1 3 56 78 34 6
41
Array doesn't have two elements with given sum 41

Weightage - 10InputOutput
8
12 34 56 78 90 98 76 54
99
Array doesn't have two elements with given sum 99

Weightage - 15Sample InputSample Output


6
1 4 45 6 10 8
16
Array has two elements with given sum 16

Sample InputSample Output


6
1 4 45 6 10 8
60
Array doesn't have two elements with given sum 60

Solution
import java.util.Scanner;
import java.util.Arrays;

class Main {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = sc.nextInt();
}
int sum = sc.nextInt();

if (hasTwoElementsWithSum(arr, sum)) {
System.out.println("Array has two elements with given sum " + sum);
} else {
System.out.println("Array doesn't have two elements with given sum " +
sum);
}
}

static boolean hasTwoElementsWithSum(int[] arr, int sum) {


int n = arr.length;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (arr[i] + arr[j] == sum) {
return true;
}
}
}
return false;
}
}

Q15Test CaseInputOutput
10 10
1 2 3 4 5 6 7 8 9 10
5 6 7 8 6 5 3 2 1 8
9 1 3 4 1 4 5 8 9 10
5 3 5 1 3 5 6 2 7 2
1 2 3 4 5 6 7 8 9 10
5 6 7 8 6 5 3 2 1 8
9 1 3 4 1 4 5 8 9 10
5 3 5 1 3 5 6 2 7 2
1 2 3 4 5 6 7 8 9 10
5 6 7 8 6 5 3 2 1 8
45

Weightage - 25InputOutput
8 10
1 2 3 4 5 6 7 8 9 10
5 6 7 8 6 5 3 2 1 8
9 1 3 4 1 4 5 8 9 10
5 3 5 1 3 5 6 2 7 2
1 2 3 4 5 6 7 8 9 10
5 6 7 8 6 5 3 2 1 8
9 1 3 4 1 4 5 8 9 10
5 3 5 1 3 5 6 2 7 2
28

Weightage - 25InputOutput
2 2
74 85
96 52
126

Weightage - 15InputOutput
1 1
25
25
Weightage - 10InputOutput
2 2
1 4
6 8
9

Weightage - 15InputOutput
4 4
1 5 6 4
3 5 7 4
7 8 5 3
3 5 7 4
15

Weightage - 10Sample InputSample Output


3 3
1 2 3
4 5 6
7 8 9
15

Sample InputSample Output


4 4
12 23 45 56
78 89 98 87
65 54 32 21
14 25 36 58
191

Solution
import java.util.Scanner;
class disgonalSum
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);

int i,j,row,col,sum=0;
row = sc.nextInt();
col = sc.nextInt();

int[][] mat = new int[row][col];


for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
mat[i][j] = sc.nextInt();
}
}

for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
if(i==j)
{
sum = sum + mat[i][j];
}
}
}

System.out.println(sum) ;
}
}

Q16Test CaseInputOutput
9 6
15

Weightage - 10InputOutput
-3 -3
-3

Weightage - 15InputOutput
90 101
127

Weightage - 15InputOutput
0 76
76

Weightage - 25InputOutput
-155 -89
-25

Weightage - 25InputOutput
34 89
123

Weightage - 10Sample InputSample Output


78 90
94

Sample InputSample Output


5 7
7
Solution
import java.util.Scanner;
class Main{
public static void main(String[] args) {

int number1, number2, result;


Scanner sc=new Scanner(System.in);
number1=sc.nextInt();
number2=sc.nextInt();
result = number1 | number2;
System.out.println(result);
}
}

Q17Test CaseInputOutput
abbbabbbab
3

Weightage - 10InputOutput
bbbbaaaaaa
4

Weightage - 15InputOutput
aaaaabbbbbbb
5

Weightage - 15InputOutput
aaabbbbbbaab
5

Weightage - 25InputOutput
abab
2

Weightage - 10InputOutput
ababaaaabbbbaaabb
8

Weightage - 25Sample InputSample Output


aabbb
2

Sample InputSample Output


baaba
2
Solution
import java.io.*;
import java.util.*;
class ColourfulBalloons {
public static void main(String [] args) {
int i,a=0,b=0;
String str;
Scanner sc = new Scanner(System.in);
str = sc.next();
for(i=0;i<str.length();i++)
{
if(str.charAt(i)==97) {
a++;
}
else {
b++;
}
}
if(a>b) {
System.out.println(b);
}
else {
System.out.println(a);
}
}
}

Q18Test CaseInputOutput
9
1 2 4 5 6 7 9 7 8
6

Weightage - 15InputOutput
5
1 2 4 5 6
3

Weightage - 10InputOutput
20
2 5 6 7 9 8 1 3 11 13 15 17 19 20 12 14 16 18 10 21
4

Weightage - 25InputOutput
10
10 6 5 7 1 2 3 4 9 11
8

Weightage - 25InputOutput
3
1 3 4
2

Weightage - 10InputOutput
4
1 2 4 5
3

Weightage - 15Sample InputSample Output


5
6 4 3 2 1
5

Sample InputSample Output


15
4 6 5 7 3 1 2 9 8 10 12 15 14 13 16
11

Solution
import java.util.*;
class Main
{
public static void main(String[] args) {
int sum = 0;
int idx = -1;
int num;
Scanner sc=new Scanner(System.in);
num=sc.nextInt();
int arr[]=new int[num];
for(int i=0;i<num;i++)
{
arr[i]=sc.nextInt();
sum += arr[i];
}
int total = (num+2)*(num+1)/ 2;

System.out.println("" + (total - sum));


}
}

Q19Test CaseInputOutput
1
1 is not prime number

Weightage - 10InputOutput
2
2 is prime number

Weightage - 10InputOutput
456
456 is not prime number

Weightage - 15InputOutput
37
37 is prime number

Weightage - 25InputOutput
6
6 is not prime number

Weightage - 15InputOutput
3
3 is prime number

Weightage - 25Sample InputSample Output


7
7 is prime number

Sample InputSample Output


9
9 is not prime number

Solution
import java.util.*;
class Main
{
public static void main(String args[]){
int i,flag=0;
int n;
Scanner in = new Scanner(System.in);
n=in.nextInt();
if(n==0||n==1)
{
System.out.println(n+" is not prime number");
}else
{
for(i=2;i<=n/2;i++)
{
if(n%i==0)
{
System.out.println(n+" is not prime number");
flag=1;
break;
}
}
if(flag==0)
{
System.out.println(n+" is prime number");
}
}
}
}

Q20Test CaseInputOutput
25000.0
75000.0
15825.0
52485.0
Total expenses : Rs.168310.00
Branding expenses percentage : 14.85%
Travel expenses percentage : 44.56%
Food expenses percentage : 9.40%
Logistics expenses percentage : 31.18%

Weightage - 10InputOutput
856985.0
745874.0
145254.0
256365.0
Total expenses : Rs.2004478.00
Branding expenses percentage : 42.75%
Travel expenses percentage : 37.21%
Food expenses percentage : 7.25%
Logistics expenses percentage : 12.79%

Weightage - 15InputOutput
256321.0
452145.0
748896.0
965874.0
Total expenses : Rs.2423236.00
Branding expenses percentage : 10.58%
Travel expenses percentage : 18.66%
Food expenses percentage : 30.90%
Logistics expenses percentage : 39.86%

Weightage - 25InputOutput
85698.0
96588.0
74589.0
98589.0
Total expenses : Rs.355464.00
Branding expenses percentage : 24.11%
Travel expenses percentage : 27.17%
Food expenses percentage : 20.98%
Logistics expenses percentage : 27.74%

Weightage - 25InputOutput
85558.0
87455.0
96999.0
98588.0
Total expenses : Rs.368600.00
Branding expenses percentage : 23.21%
Travel expenses percentage : 23.73%
Food expenses percentage : 26.32%
Logistics expenses percentage : 26.75%

Weightage - 15InputOutput
1234.0
8736.0
1632.0
1890.0
Total expenses : Rs.13492.00
Branding expenses percentage : 9.15%
Travel expenses percentage : 64.75%
Food expenses percentage : 12.10%
Logistics expenses percentage : 14.01%

Weightage - 10Sample InputSample Output


20000.0
40000.0
15000.0
25000.0
Total expenses : Rs.100000.00
Branding expenses percentage : 20.00%
Travel expenses percentage : 40.00%
Food expenses percentage : 15.00%
Logistics expenses percentage : 25.00%

Solution
import java.util.*;
import java.io.*;
import java.math.*;
import java.text.*;
class Totalexpenses {
public static void main(String [] args) {
double branding,travel,food,logistics,sum = 0.00;
DecimalFormat d = new DecimalFormat("0.00");
Scanner sc=new Scanner(System.in);
branding = sc.nextDouble();
travel = sc.nextDouble();
food = sc.nextDouble();
logistics = sc.nextDouble();
sum = branding+travel+food+logistics;
System.out.println("Total expenses : Rs." +d.format(sum));
System.out.println("Branding expenses percentage : "
+d.format((branding/sum)*100) +"%");
System.out.println("Travel expenses percentage :
"+d.format((travel/sum)*100) +"%");
System.out.println("Food expenses percentage :
"+d.format((food/sum)*100) +"%");
System.out.println("Logistics expenses percentage :
"+d.format((logistics/sum)*100) +"%");
}
}

You might also like