Language: C++

import java.util.Scanner; 

 class Main{
 public static void main(String[] args){
 Scanner sc=new Scanner(System.in);
 int H=sc.nextInt();
 int W=sc.nextInt();
 char[][] k=new char[H][W];
 for(int i=0; i< H; i++){
String line=sc.next();
 for(int j=0; j< W; j++){
 k[i][j]=line.charAt(j);
 }
 }
 int num=0;
 for(int i=0; i<H; i++){
 for(int j=0; j<W; j++){
 if(k[i][j]!=' '){
 dfs(i,j,H,W,k);
 num++;
 }
 }
 }
 System.out.println(num);
 }
 public static void dfs(int I,int J,final int H,final int W,char[][] k){
 char p=k[I][J];
 k[I][J]=' ';
 int[] dx={-1,0,0,1};
 int[] dy={0,-1,1,0};
 for(int t=0;t<4;t++){
 if(p==k[I+dx[t]][J+dy[t]]&&I+dx[t]>=0&&I+dx[t]<H&&J+dy[t]>=0&&J+dy[t]<W){
 dfs(I+dx[t],J+dy[t],H,W,k);
 }
 }
 return;
 }
 }

Compiler output:
a.cc:1:1: error: 'import' does not name a type
    1 | import java.util.Scanner;
      | ^~~~~~
a.cc:1:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:4:8: error: expected ':' before 'static'
    4 |  public static void main(String[] args){
      |        ^~~~~~~
      |        :
a.cc:4:26: error: 'String' has not been declared
    4 |  public static void main(String[] args){
      |                          ^~~~~~
a.cc:4:35: error: expected ',' or '...' before 'args'
    4 |  public static void main(String[] args){
      |                                   ^~~~
a.cc:26:8: error: expected ':' before 'static'
   26 |  public static void dfs(int I,int J,final int H,final int W,char[][] k){
      |        ^~~~~~~
      |        :
a.cc:26:37: error: 'final' has not been declared
   26 |  public static void dfs(int I,int J,final int H,final int W,char[][] k){
      |                                     ^~~~~
a.cc:26:37: error: two or more data types in declaration of 'H'
a.cc:26:48: error: expected ')' before ',' token
   26 |  public static void dfs(int I,int J,final int H,final int W,char[][] k){
      |                        ~                       ^
      |                                                )
a.cc:26:49: error: variable or field 'final' declared void
   26 |  public static void dfs(int I,int J,final int H,final int W,char[][] k){
      |                                                 ^~~~~
a.cc:26:49: error: expected ';' at end of member declaration
   26 |  public static void dfs(int I,int J,final int H,final int W,char[][] k){
      |                                                 ^~~~~
      |                                                      ;
a.cc:26:61: error: expected unqualified-id before 'char'
   26 |  public static void dfs(int I,int J,final int H,final int W,char[][] k){
      |                                                             ^~~~
a.cc:38:3: error: expected ';' after class definition
   38 |  }
      |   ^
      |   ;
a.cc: In static member function 'static void Main::main(int*)':
a.cc:5:2: error: 'Scanner' was not declared in this scope
    5 |  Scanner sc=new Scanner(System.in);
      |  ^~~~~~~
a.cc:6:8: error: 'sc' was not declared in this scope
    6 |  int H=sc.nextInt();
      |        ^~
a.cc:8:6: error: structured binding declaration cannot have type 'char'
    8 |  char[][] k=new char[H][W];
      |      ^~
a.cc:8:6: note: type must be cv-qualified 'auto' or reference to cv-qualified 'auto'
a.cc:8:6: error: empty structured binding declaration
a.cc:8:8: error: expected initializer before '[' token
    8 |  char[][] k=new char[H][W];
      |        ^
a.cc:10:1: error: 'String' was not declared in this scope
   10 | String line=sc.next();
      | ^~~~~~
a.cc:12:2: error: 'k' was not declared in this scope
   12 |  k[i][j]=line.charAt(j);
      |  ^
a.cc:12:10: error: 'line' was not declared in this scope
   12 |  k[i][j]=line.charAt(j);
      |          ^~~~
a.cc:18:5: error: 'k' was not declared in this scope
   18 |  if(k[i][j]!=' '){
      |     ^
a.cc:24:2: error: 'System' was not declared in this scope
   24 |  System.out.println(num);
      |  ^~~~~~