Bubble Sort Without User Input
public class BubbleSort {
public static void main(String[] args) {
int array[]={5,8,7,3,2,9,6,12,13,15,174,18,200};
int temp;
for (int i=0;i<array.length;i++)
{
for(int j=0;j<array.length-1;j++){
if(array[j]>array[j+1]){
temp=array[j];
array[j]=array[j+1];
array[j+1]=temp;
}
}
}
for (int i=0;i<array.length;i++){
System.out.print(array[i]+" ");
}
}
}
Output :
public class BubbleSort {
public static void main(String[] args) {
int array[]={5,8,7,3,2,9,6,12,13,15,174,18,200};
int temp;
for (int i=0;i<array.length;i++)
{
for(int j=0;j<array.length-1;j++){
if(array[j]>array[j+1]){
temp=array[j];
array[j]=array[j+1];
array[j+1]=temp;
}
}
}
for (int i=0;i<array.length;i++){
System.out.print(array[i]+" ");
}
}
}
Output :
Click to next or Searching Programs
Start
with your Choice
-Important Programs for
Freshers
- Palindrome Number
- Prime Number
- Swapping Number
- Leap Year
- Odd and Even Number
- Fibonacci Series
- Armstrong Number
- Factorial Number
- Print Table
Learn
Pattern Programs
- Alphabet pattern
program in java
- Square pattern
programs in java
- Diamond Star pattern
programs in java
- Number Pattern
Programs in java
- Diagonal pattern
program in java
Click to
learn Array Programs
- 4 ways to print
Array in Java
- 2D Array in Java
- Anonymous Array in
Java
- Single
Dimensional Array in Java
- Find Second Largest
Number in Array
- Delete an Element in
Array in Java
- Common Element in
Array in Java
- Missing Element in
Array
- Insert Element in
Array
- Smallest and Largest
Elements in Array
- Find Odd and Even
Number in Array
Click
to Learn
MySQL
Learn with us | HTML | CSS | JS | Bootstrap | JAVA | ADV JAVA
| SQL | GIT
No comments:
Post a Comment