Language: Java

#include <bits/stdc++.h>
using namespace std;
int H,W,sx,sy,gx,gy,d[1000][1000];
string s[1000];
int INF=1<<30;
main()
{
    cin>>H>>W;
    cin>>sx>>sy;
    cin>>gx>>gy;
    --sx;--sy;--gx;--gy;
    for(int i=0;i<H;++i)cin>>s[i];
    for(int i=0;i<H;++i)for(int j=0;j<W;++j)d[i][j]=INF;
    d[sx][sy]=0;
    deque<pair<int,int>>q;
    q.push_back({sx,sy});
    while(!q.empty())
    {
        int x=q.front().first;
        int y=q.front().second;
        q.pop_front();
        for(int i=-2;i<=2;++i)for(int j=-2;j<=2;++j)
        {
            int nx=x+i;
            int ny=y+j;
            if(nx<0||ny<0||nx>=H||ny>=W||s[nx][ny]=='#')continue;
            if(abs(i)+abs(j)<=1&&d[nx][ny]>d[x][y])
            {
                d[nx][ny]=d[x][y];
            }else if(d[nx][ny]>d[x][y]+1)
            {
                d[nx][ny]=d[x][y]+1;
            }else continue;
            q.push_back({nx,ny});
        }
    }
    cout<<(d[gx][gy]==INF?-1:d[gx][gy])<<endl;
}

Compiler output:
Main.java:1: error: illegal character: '#'
#include <bits/stdc++.h>
^
Main.java:1: error: class, interface, enum, or record expected
#include <bits/stdc++.h>
         ^
Main.java:3: error: class, interface, enum, or record expected
int H,W,sx,sy,gx,gy,d[1000][1000];
^
Main.java:4: error: class, interface, enum, or record expected
string s[1000];
^
Main.java:5: error: unnamed classes are a preview feature and are disabled by default.
int INF=1<<30;
^
  (use --enable-preview to enable unnamed classes)
Main.java:6: error: class, interface, enum, or record expected
main()
^
Main.java:9: error: class, interface, enum, or record expected
    cin>>sx>>sy;
    ^
Main.java:10: error: class, interface, enum, or record expected
    cin>>gx>>gy;
    ^
Main.java:11: error: class, interface, enum, or record expected
    --sx;--sy;--gx;--gy;
    ^
Main.java:11: error: class, interface, enum, or record expected
    --sx;--sy;--gx;--gy;
         ^
Main.java:11: error: class, interface, enum, or record expected
    --sx;--sy;--gx;--gy;
              ^
Main.java:11: error: class, interface, enum, or record expected
    --sx;--sy;--gx;--gy;
                   ^
Main.java:12: error: class, interface, enum, or record expected
    for(int i=0;i<H;++i)cin>>s[i];
    ^
Main.java:12: error: class, interface, enum, or record expected
    for(int i=0;i<H;++i)cin>>s[i];
                ^
Main.java:12: error: class, interface, enum, or record expected
    for(int i=0;i<H;++i)cin>>s[i];
                    ^
Main.java:13: error: class, interface, enum, or record expected
    for(int i=0;i<H;++i)for(int j=0;j<W;++j)d[i][j]=INF;
    ^
Main.java:13: error: class, interface, enum, or record expected
    for(int i=0;i<H;++i)for(int j=0;j<W;++j)d[i][j]=INF;
                ^
Main.java:13: error: class, interface, enum, or record expected
    for(int i=0;i<H;++i)for(int j=0;j<W;++j)d[i][j]=INF;
                    ^
Main.java:13: error: class, interface, enum, or record expected
    for(int i=0;i<H;++i)for(int j=0;j<W;++j)d[i][j]=INF;
                                    ^
Main.java:13: error: class, interface, enum, or record expected
    for(int i=0;i<H;++i)for(int j=0;j<W;++j)d[i][j]=INF;
                                        ^
Main.java:14: error: class, interface, enum, or record expected
    d[sx][sy]=0;
    ^
Main.java:16: error: class, interface, enum, or record expected
    q.push_back({sx,sy});
    ^
Main.java:17: error: class, interface, enum, or record expected
    while(!q.empty())
    ^
Main.java:21: error: class, interface, enum, or record expected
        q.pop_front();
        ^
Main.java:22: error: class, interface, enum, or record expected
        for(int i=-2;i<=2;++i)for(int j=-2;j<=2;++j)
        ^
Main.java:22: error: class, interface, enum, or record expected
        for(int i=-2;i<=2;++i)for(int j=-2;j<=2;++j)
                     ^
Main.java:22: error: class, interface, enum, or record expected
        for(int i=-2;i<=2;++i)for(int j=-2;j<=2;++j)
                          ^
Main.java:22: error: class, interface, enum, or record expected
        for(int i=-2;i<=2;++i)for(int j=-2;j<=2;++j)
                                           ^
Main.java:22: error: class, interface, enum, or record expected
        for(int i=-2;i<=2;++i)for(int j=-2;j<=2;++j)
                                                ^
Main.java:26: error: class, interface, enum, or record expected
            if(nx<0||ny<0||nx>=H||ny>=W||s[nx][ny]=='#')continue;
            ^
Main.java:27: error: class, interface, enum, or record expected
            if(abs(i)+abs(j)<=1&&d[nx][ny]>d[x][y])
            ^
Main.java:30: error: class, interface, enum, or record expected
            }else if(d[nx][ny]>d[x][y]+1)
            ^
Main.java:33: error: class, interface, enum, or record expected
            }else continue;
            ^
Main.java:34: error: class, interface, enum, or record expected
            q.push_back({nx,ny});
            ^
Main.java:35: error: class, interface, enum, or record expected
        }
        ^
Main.java:38: error: class, interface, enum, or record expected
}
^
36 errors