-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbubble.java
60 lines (60 loc) · 1.33 KB
/
bubble.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import java.util.*;
class bubble
{
int x[][],y[],m,n;
bubble(int m1)
{
m=m1;
x =new int[m][m];
y= new int[m*m];
}
Scanner sc=new Scanner (System.in);
void input()
{
System.out.println("Enter Elements Array");
for (int i=0;i<m;i++)
{
for (int j=0;j<m;j++)
x[i][j]=sc.nextInt();
}
}
void calc()
{
int temp=0;
for (int k=0;k<m;k++)
{
for (int i=0;i<m;i++)
{
for (int j=0;j<m-i-1;j++)
{
if (x[k][j]>x[k][j+1])
{
temp= x[k][j];
x[k][j]=x[k][j+1];
x[k][j+1]=temp;
}
}
}
}
}
void display()
{
System.out.println("Output");
for (int i=0;i<m;i++)
{
for(int j=0;j<m;j++)
System.out.print(x[j][i]+" ");
System.out.println();
}
}
public static void main(String args[])
{
Scanner sc=new Scanner (System.in);
System.out.println("Enter row and columns of matrix");
int m=sc.nextInt();
bubble obj=new bubble (m);
obj.input();
obj.calc();
obj.display();
}
}