Im having toruble in JAVA of a program hat implements the Floyd… Im having toruble in JAVA of a program hat implements the Floyd algorithm

Im having toruble in JAVA of a program hat implements the Floyd… Im having toruble in JAVA of a program hat implements the Floyd algorithm to display all-pairs shortest pathsImage transcription textInput format: This is a sample inputfrom a user. 0 -1 3 -1 20-1-1 -1701 6 -1 -10 The first line (= 4 in the … Show more… Show moreyou can assume that the number of vertices is less than 25.Image transcription textSample Run 0: Assume that the usertyped the following lines -1 3 -1 20-1-1-1701 6-1 -1 0… Show more and Image transcription text0 10 3 4 4056 7701 6 16 9 0 SampleRun 1: Assume that the user typed thefollowing lines 0 2-1 -102 2… Show more… Show moreand sample 2Image transcription textSample Run 2: Assume that the usertyped the following lines 4 0 10 -1 -1 -1 015 -1 -1 -1 0 20 50 -1 -1 0 T… Show more… Show moreand this si smy code that kept giving me the wrong answer…  import java.io.*;class Main { final static int INF = 9999, nV = 4; // Implementing floyd warshall algorithm void floydWarshall(int graph[][]) { int matrix[][] = new int[nV][nV]; int i, j, k; for (i = 0; i < nV; i++) for (j = 0; j < nV; j++) matrix[i][j] = graph[i][j]; // Adding vertices individually for (k = 0; k < nV; k++) { for (i = 0; i < nV; i++) { for (j = 0; j < nV; j++) { if (matrix[i][k] + matrix[k][j] < matrix[i][j]) matrix[i][j] = matrix[i][k] + matrix[k][j]; } } } printMatrix(matrix); } void printMatrix(int matrix[][]) { for (int i = 0; i < nV; ++i) { for (int j = 0; j < nV; ++j) { if (matrix[i][j] == INF) System.out.print("INF "); else System.out.print(matrix[i][j] + " "); } System.out.println(); } } public static void main(String[] args) { int graph[][] = { { 0, 3, INF, 5 }, { 2, 0, INF, 4 }, { INF, 1, 0, INF }, { INF, INF, 2, 0 } }; FloydWarshall a = new FloydWarshall(); a.floydWarshall(graph); }} Computer Science Engineering & Technology Java Programming CS 38 Share QuestionEmailCopy link