-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patharray_bubble_char.java
39 lines (38 loc) · 960 Bytes
/
array_bubble_char.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package com.mycompany.noor;
import java.util.Scanner;
public class array_bubble_char
{//ascending
void bubblesort()
{
char c[],temp;
int i,j,n;
Scanner sc=new Scanner(System.in);
System.out.println("Enter number of elements");
n=sc.nextInt();
c=new char[n];
System.out.println("Enter "+n+" characters");
for(i=0;i<n;i++)
{
c[i]=sc.next().charAt(0);
}
for(i=0;i<n;i++)
{
for(j=0;j<(n-1);j++)
{
if(c[j]>c[j+1])
{
temp=c[j];
c[j]=c[j+1];
c[j+1]=temp;
}
}
}
for(i=0;i<n;i++)
System.out.print(c[i]+" ");
}
public static void main(String args[])
{
array_bubble_char obj=new array_bubble_char();
obj.bubblesort();
}
}