Java Problems (Logical Programs) : Sorting
Java Problems (Logical Programs) : Sorting
Sorting
Array Ascending order(Number), ex. {2,4,3,1,8,5,6} {1,2,3,4,5,6,8}
Array Descending order(Number) , ex. {2,4,3,1,8,5,6} {8,6,5,4,3,2,1}
Flipping of Array , ex. {1,2,3,4,5,6,8} {8,6,5,4,3,2,1}
Character Sorting, ex. {f,g,a,c,d,b,e} {a,b,c,d,e,f,g}
Finding Values
Mathematical Problems
Decimal to Binary ex. Input = 6 0110
Binary to Decimal ex. Input = 0110 6
Adding all numbers in a single Integer input
Input Validation
Average Computation
Two Dimensional Array’s
Number Series
Arithmetic, ex. 1 , 4 , 7 , 10, 13 , 16
Cube, ex. 1 , 8 , 27 , 64 , 125
Even, ex. 2 , 4 , 6 , 8 , 10
Odd, ex 1 , 3 , 5 , 7 , 9
Fibonacci, ex. 1 , 1 , 2 , 3 , 5 , 8 , 13 , 21 , 34
Geometric, ex. 5 , 10 , 20 , 40 , 80 , 160 , 320
Prime, ex. 2 , 3 , 5 , 7 , 11 , 13 , 17 , 19 , 23
Square, ex. 1 , 4 , 9 , 16 , 25 , 36 , 49 , 64
Triangular, ex. 1 , 3 , 6 , 10 , 15 , 21 , 28
Patterns
Cross
Diamond
Pyramid
Inverted Pyramid
Java Logical Problems Codes
Sorting
while(Increment != first_Array.length*first_Array.length)
{
for (int firstIndex = 0; firstIndex <first_Array.length-1; firstIndex++)
{
for (int Loop = firstIndex; Loop < firstIndex+1; Loop++)
{
if(first_Array[firstIndex] >= first_Array[firstIndex+1])
{
greaterNumber = first_Array[firstIndex];
first_Array[firstIndex] = first_Array[firstIndex+1];
first_Array[firstIndex+1] = greaterNumber;
}
}
}
//Increment by 1 until the value reaches the length of Array
Increment++;
}
//Print Array values in ascending order
System.out.print("Ascending order: ");
for (int arrayIndex = 0; arrayIndex < first_Array.length; arrayIndex++)
{
System.out.print(first_Array[arrayIndex]+" ");
}
Array Descending order(Number) , ex. {2,4,3,1,8,5,6} {8,6,5,4,3,2,1}