Professional Documents
Culture Documents
For Interview
For Interview
For Interview
FACTORIAL
2.PRIME NUMBER
3.INTEGER REVERSE
4.STRING REVERSE
5.INTEGER PALINDROME
6.STRING PALINDROME
7.ARMSTRONG
8.FIBINOCCI
9.LEAP YEAR
10.SWAPPING OF TWO NUMBERS
18.ARRAYS EQUAL
19.MISSING ELEMENT IN ARRAY
24.DUPLICATES IN ARRAY
30.Transposing matrices
public class MatrixTranspose {
public static void main(String[] args) {
int[][] originalMatrix = {
{ 1, 2, 3 },
{ 4, 5, 6 },
{ 7, 8, 9 }
};
36.PERMUTATIONS
37.VOWELS IN STRING
38.OCCURENCE OF CHAR
43.INSERTION SORT
Design pattrens:
int rows = 5;
int spaces = rows - 1;
// Upper half of the diamond
for (int i = 0; i < rows; i++) {
// Print leading spaces
for (int j = 0; j < spaces - i; j++) {
System.out.print(" ");
}
// Print stars
for (int k = 0; k < 2 * i + 1; k++) {
System.out.print("*");
}
System.out.println();
}
// Lower half of the diamond
for (int i = rows - 2; i >= 0; i--) {
// Print leading spaces
for (int j = 0; j < spaces - i; j++) {
System.out.print(" ");
}
// Print stars
for (int k = 0; k < 2 * i + 1; k++) {
System.out.print("*");
}
System.out.println();
}
3.Pascal’s Triangle
public class PascalsTriangle {
int number = 1;
for (int j = 0; j <= i; j++) {
// Print the current number
System.out.print(number + " ");
System.out.println();
}
}
}
int rows = 5;
System.out.println();
}
2.Solid Rectangle
int rows = 4;
int columns = 6;