rendered paste bodyimport java.util.*;public class KnightsTour1{int[][] array;int knightRow;int knightCol;private int counter;Random rand = new Random();//move component arraysint[] horizontal = {1, 2, 2, 1, -1, -2, -2, -1};int[] vertical = {-2, -1, 1, 2, 2, 1, -1, -2};public KnightsTour1(){array = new int[8][8];knightRow = 0;knightCol = 0;counter = 1;array[knightRow][knightCol] = 1;}public void printTable(){System.out.print(" ");for(int i = 0; i < 8; i++){System.out.printf("%4d", i+1);}System.out.println() ;for(int row = 0; row < 8; row++){System.out.print(row+1);for(int col = 0; col < 8; col++){System.out.printf("%4d", array[row][col]);}System.out.println() ;}}//checks if knight can make a valid movepublic boolean canMove(){int row, col = 0;int moveNumber = 0;moveNumber = rand.nextInt(eight) ;row = knightRow + vertical[moveNumber];col = knightRow + horizontal[moveNumber];if(row >= 0 && row <= 8 && col >= 0 && col <= 8 && array[row][col] == 0)return true;return false;}public void move(){int row = knightRow;int col = knightCol;int moveNumber = 0;int[] horizontal = {1, 2, 2, 1, -1, -2, -2, -1};int[] vertical = {-2, -1, 1, 2, 2, 1, -1, -2};do{moveNumber = rand.nextInt(eight) ;row = knightRow + vertical[moveNumber];col = knightCol + horizontal[moveNumber];}while(row < 0 || row > 8 || col < 0 || col > 8 || array[row][col] != 0);knightRow = row;knightCol = col;counter++;array[row][col] = counter;}public int getCount(){return counter;}}//main:public class KnightTourDriver{public static void main(String [] args){KnightsTour1 eddie = new KnightsTour1();eddie.move() ;eddie.printTable() ;System.out.println(eddie.getCount() + " Squares were visited");}}