1.
Write a Java program to print the contents of a two-dimensional Boolean array where t will
represent true and f will represent false.
Sample array:
array = {{true, false, true},
{false, true, false}};
Expected Output :
tft
ftf
2. Write a Java program to print an array after changing the rows and columns of a given two-
dimensional array.
Original Array:
10 20 30
40 50 60
After changing the rows and columns of the said array:
10 40
20 50
30 60
3. Write a Java program to find the k largest elements in a given array. Elements in the array can
be in any order.
Expected Output:
Original Array:
[1, 4, 17, 7, 25, 3, 100]
3 largest elements of the said array are:
100 25 17
4. Write a Java program to find the k smallest elements in a given array. Elements in the array can
be in any order.
Expected Output:
Original Array:
[1, 4, 17, 7, 25, 3, 100]
3 largest elements of the said array are:
100 25 17
5. Write a Java program to find the kth smallest and largest element in a given array. Elements in
the array can be in any order.
Expected Output:
Original Array:
[1, 4, 17, 7, 25, 3, 100]
K'th smallest element of the said array:
K'th largest element of the said array:
25
6. Write a Java program to find the numbers greater than the average of the numbers of a given
array.
Expected Output:
Original Array:
[1, 4, 17, 7, 25, 3, 100]
The average of the said array is: 22.0
The numbers in the said array that are greater than the average are:
25
100
7. Write a Java program to move every positive number to the right and every negative number to
the left of a given array of integers.
Expected Output:
Original array: [-2, 3, 4, -1, -3, 1, 2, -4, 0]
Result: [-4, -3, -2, -1, 0, 1, 2, 3, 4]
8. Write a Java program to accept two string and test if the second string contains the first one.
Input first string: Once in a blue moon
Input second string: See eye to eye
If the second string contains the first one? False
9. Write a Java program to print the number of prime numbers which are less than or equal to a
given integer.
Input:
n (1 ≤ n ≤ 999,999)
Expected Output:
Input the number(n):
1235
Number of prime numbers which are less than or equal to n.:
202
10. Write a Java program to replace a string "python" with "java" and "java" with "python" in a
given string.
Input:
English letters (including single byte alphanumeric characters, blanks, symbols) are given
on one line. The length of the input character string is 1000 or less.
Output:
Exchanged character string of python and java on one line.
Expected Output:
Input the string:
python is more propular than java
New string:
java is more propular than python