Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hacktoberfest-2022 #242

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions Sorting/sorting.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Java Program to sort an elements
// by bringing Arrays into play

// Main class
class GFG {

// Main driver method
public static void main(String[] args)
{

// Custom input array
int arr[] = { 4, 3, 2, 1 };

// Outer loop
for (int i = 0; i < arr.length; i++) {

// Inner nested loop pointing 1 index ahead
for (int j = i + 1; j < arr.length; j++) {

// Checking elements
int temp = 0;
if (arr[j] < arr[i]) {

// Swapping
temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}

// Printing sorted array elements
System.out.print(arr[i] + " ");
}
}
}