-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWarshall.java
More file actions
60 lines (60 loc) · 932 Bytes
/
Copy pathWarshall.java
File metadata and controls
60 lines (60 loc) · 932 Bytes
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 Warshall
{
int w[][]=new int [30][30];
int D[][]=new int [30][30];
int n,i,j,k;
void input()
{
Scanner d=new Scanner(System.in);
System.out.println("Enter the Limit:");
n=d.nextInt();
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
w[i][j]=d.nextInt();
}
System.out.println("Given Matrix:");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
System.out.print(" "+w[i][j]);
System.out.print("\n");
}
}
void logic()
{
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
for(k=0;k<n;k++)
{
D[j][k]=(w[j][i]&w[i][k]);
if(w[j][k]<D[j][k])
w[j][k]=D[j][k];
}
}
}
}
void out()
{
System.out.println("Resultant Matrix::");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
System.out.print(" "+w[i][j]);
System.out.print("\n");
}
}
}
class Hari
{
public static void main(String []arg)
{
Warshall m=new Warshall();
m.input();
m.logic();
m.out();
}
}