package bgp;
import java.util.*;
public class rout
{
public static void
main(String[] args)
{
int i,j,k;
int a[][]=new
int[10][10];
int b[][]=new
int[10][10];
Scanner z=new
Scanner(System.in);
System.out.print("Enter the number of nodes :");
int
n=z.nextInt();
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
System.out.println("Enter the distance between the
host"+(i+1)+"-"+(j+1));
a[i][j]=z.nextInt();
}
System.out.println("\nThe
matrix is:");
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
System.out.print(a[i][j]+"\t");
}
System.out.println();
}
for(k=0;k<n;k++)
{
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(a[i][j]>a[i][k]+a[k][j])
{
a[i][j]=a[i][k]+a[k][j];
}
}
}
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
b[i][j]=a[i][j];
if(i==j)
{
b[i][j]=0;
}
}
}
System.out.println("\nThe output matrix is:");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
System.out.print(b[i][j]+"\t");
}
System.out.println("\n");
}
}