Java Test - Day 1 - July 1
Java Test - Day 1 - July 1
Java Test - Day 1 - 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.
Q2.
Problem Statement
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.
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."
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.
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.
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:
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).
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:
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:
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.
Q12.
Problem Statement
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"
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>>"
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?
Q16.
Problem Statement
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.
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.
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.
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.
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
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
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
Solution
import java.util.Scanner;
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
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
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
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
Solution
import java.util.Scanner;
class j5 {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int num;
num = sc.nextInt();
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
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
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
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
Solution
import java.util.Scanner;
class Main {
int n1 = s.nextInt();
double n2 = s.nextDouble();
boolean n3 = s.nextBoolean();
s.nextLine();
char c = s.nextLine().charAt(0);
String n4 = s.nextLine();
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
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
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);
}
class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n, sum = 0;
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
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
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);
}
}
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
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();
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
Q17Test CaseInputOutput
abbbabbbab
3
Weightage - 10InputOutput
bbbbaaaaaa
4
Weightage - 15InputOutput
aaaaabbbbbbb
5
Weightage - 15InputOutput
aaabbbbbbaab
5
Weightage - 25InputOutput
abab
2
Weightage - 10InputOutput
ababaaaabbbbaaabb
8
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
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;
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
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%
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) +"%");
}
}