Knight moves in a 8*8 chess board The problem that I have is to find the minimum number of ways to go from one box to another box of a chess board. Now, I have created a code which is not very elegant but works. I am interested in if the code will give me the correct answer. Here is the code:

import java.util.*;
class Main{
  public static void main(String []sad){
    String str[] = new String[]{"2 1", "1 2","-1 -2","-1 2","1 -2","2 -1","-2 1","-2 -1"};
    String start = "8,8";
    Set&lt;String&gt; set = new HashSet&lt;String&gt;();
    String goal = "1,1";
    int s0 = Integer.parseInt(start.split(",")[0]);
      int s1 = Integer.parseInt(start.split(",")[1]);
      int s2 = Integer.parseInt(goal.split(",")[0]);
      int s3 = Integer.parseInt(goal.split(",")[1]);
    int dist = 0;
    Stack&lt;String&gt; stk = new Stack&lt;String&gt;();
    stk.push(start);
    set.add(start);
    while(!stk.empty()){
      dist++;
      String ele = stk.pop();
      for(int i=0;i&lt;str.length;i++){
        int d0 = Integer.parseInt(ele.split(",")[0]) + Integer.parseInt(str[i].split(" ")[0]);
        int d1 = Integer.parseInt(ele.split(",")[1]) + Integer.parseInt(str[i].split(" ")[1]);
        if(d0&lt;1 || d0&gt;8 || d1&lt;1 || d1&gt;8)
          System.out.println("No Pushing allowed");
        else{
        String sr = d0+","+d1;
        System.out.println(sr);
        if(sr.equals(goal)){
          System.out.println("YES "+dist);
          return;}
          if(!set.contains(sr))
          {
            set.add(sr);
            stk.push(sr);
          }
      }
      }
    }
  }
}


Thanks.
First of all, you're using a wrong algorithm. A depth-first finds some path, but not necessarily the shortest one. What you actually need is a breadth-first search. You can just use a queue instead of a stack to fix it. 

Storing everything as a string is bad idea. You code'll be much better if you use appropriate data types. The position on the board or a shift vector for one move is not string. I'd suggest to create a separate Position class that holds a pair of integers to represent a position on the board and has a shiftBy and an isValid method (to get the next position after one move and to check if a position is valid). 

I'd also recommend to separate the code that reads the data and prints the result from the part that actually runs the computations. 

Fixing the indentation and spacing of code according to the Java coding convention would make it more readable. 

The names of the variables are also not very descriptive. For instance, what does ele mean? What is str (which is, in fact, not really a string)? I have no clue. It should be something like currentPosition and shiftVector because that's what it actually is.