Language: Java

import java.util.Scanner;
??
public class Main {
????????static char[][] chars;
????????static int row, col;
????????public static void main(String[] args) {
????????????????Scanner input = new Scanner(System.in);
????????????????while (true) {
????????????????????????row = input.nextInt();
????????????????????????col = input.nextInt();
????????????????????????if (row == 0 && col == 0) {
????????????????????????????????break;
????????????????????????}
????????????????????????chars = new char[row][];
????????????????????????for (int i = 0; i < row; i++) {
????????????????????????????????chars[i] = input.next().toCharArray();
????????????????????????}
????????????????????????int n = 0;
????????????????????????for (int i = 0; i < row; i++) {
????????????????????????????????for (int j = 0; j < col; j++) {
????????????????????????????????????????char symbol = chars[i][j];
????????????????????????????????????????if (symbol != '.') {
????????????????????????????????????????????????dfs(i, j, symbol);
????????????????????????????????????????????????n++;
????????????????????????????????????????}
????????????????????????????????}
????????????????????????}
????????????????????????System.out.println(n);
????????????????}
????????}
????????private static void dfs(int x, int y, char symbol) {
????????????????int dx, dy;
????????????????int[] x_mov = {-1, 0, 0, 1}, y_mov = {0, -1, 1, 0};
????????????????for (int i = 0; i < x_mov.length; i++) {
????????????????????????dx = x + x_mov[i]; dy = y + y_mov[i];
????????????????????????if (0 <= dx && dx < row && 0 <= dy && dy < col &&
????????????????????????????????????????chars[dx][dy] == symbol) {
                                chars[dx][dy] = '.';
????????????????????????????????dfs(dx, dy, symbol);
????????????????????????}
????????????????}
????????}
}

Compiler output:
Main.java:2: error: class, interface, enum, or record expected
??
^
Main.java:4: error: illegal start of type
????????static char[][] chars;
^
Main.java:5: error: illegal start of type
????????static int row, col;
^
Main.java:6: error: illegal start of type
????????public static void main(String[] args) {
^
Main.java:7: error: illegal start of expression
????????????????Scanner input = new Scanner(System.in);
^
Main.java:7: error: illegal start of expression
????????????????Scanner input = new Scanner(System.in);
 ^
Main.java:7: error: illegal start of expression
????????????????Scanner input = new Scanner(System.in);
  ^
Main.java:7: error: illegal start of expression
????????????????Scanner input = new Scanner(System.in);
   ^
Main.java:7: error: illegal start of expression
????????????????Scanner input = new Scanner(System.in);
    ^
Main.java:7: error: illegal start of expression
????????????????Scanner input = new Scanner(System.in);
     ^
Main.java:7: error: illegal start of expression
????????????????Scanner input = new Scanner(System.in);
      ^
Main.java:7: error: illegal start of expression
????????????????Scanner input = new Scanner(System.in);
       ^
Main.java:7: error: illegal start of expression
????????????????Scanner input = new Scanner(System.in);
        ^
Main.java:7: error: illegal start of expression
????????????????Scanner input = new Scanner(System.in);
         ^
Main.java:7: error: illegal start of expression
????????????????Scanner input = new Scanner(System.in);
          ^
Main.java:7: error: illegal start of expression
????????????????Scanner input = new Scanner(System.in);
           ^
Main.java:7: error: illegal start of expression
????????????????Scanner input = new Scanner(System.in);
            ^
Main.java:7: error: illegal start of expression
????????????????Scanner input = new Scanner(System.in);
             ^
Main.java:7: error: illegal start of expression
????????????????Scanner input = new Scanner(System.in);
              ^
Main.java:7: error: illegal start of expression
????????????????Scanner input = new Scanner(System.in);
               ^
Main.java:7: error: : expected
????????????????Scanner input = new Scanner(System.in);
                       ^
Main.java:7: error: : expected
????????????????Scanner input = new Scanner(System.in);
                                                      ^
Main.java:8: error: illegal start of expression
????????????????while (true) {
^
Main.java:8: error: illegal start of expression
????????????????while (true) {
 ^
Main.java:8: error: illegal start of expression
????????????????while (true) {
  ^
Main.java:8: error: illegal start of expression
????????????????while (true) {
   ^
Main.java:8: error: illegal start of expression
????????????????while (true) {
    ^
Main.java:8: error: illegal start of expression
????????????????while (true) {
     ^
Main.java:8: error: illegal start of expression
????????????????while (true) {
      ^
Main.java:8: error: illegal start of expression
????????????????while (true) {
       ^
Main.java:8: error: illegal start of expression
????????????????while (true) {
        ^
Main.java:8: error: illegal start of expression
????????????????while (true) {
         ^
Main.java:8: error: illegal start of expression
????????????????while (true) {
          ^
Main.java:8: error: illegal start of expression
????????????????while (true) {
           ^
Main.java:8: error: illegal start of expression
????????????????while (true) {
            ^
Main.java:8: error: illegal start of expression
????????????????while (true) {
             ^
Main.java:8: error: illegal start of expression
????????????????while (true) {
              ^
Main.java:8: error: illegal start of expression
????????????????while (true) {
               ^
Main.java:8: error: illegal start of expression
????????????????while (true) {
                ^
Main.java:9: error: illegal start of expression
????????????????????????row = input.nextInt();
^
Main.java:9: error: illegal start of expression
????????????????????????row = input.nextInt();
 ^
Main.java:9: error: illegal start of expression
????????????????????????row = input.nextInt();
  ^
Main.java:9: error: illegal start of expression
????????????????????????row = input.nextInt();
   ^
Main.java:9: error: illegal start of expression
????????????????????????row = input.nextInt();
    ^
Main.java:9: error: illegal start of expression
????????????????????????row = input.nextInt();
     ^
Main.java:9: error: illegal start of expression
????????????????????????row = input.nextInt();
      ^
Main.java:9: error: illegal start of expression
????????????????????????row = input.nextInt();
       ^
Main.java:9: error: illegal start of expression
????????????????????????row = input.nextInt();
        ^
Main.java:9: error: illegal start of expression
????????????????????????row = input.nextInt();
         ^
Main.java:9: error: illegal start of expression
????????????????????????row = input.nextInt();
          ^
Main.java:9: error: illegal start of expression
????????????????????????row = input.nextInt();
           ^
Main.java:9: error: illegal start of expression
????????????????????????row = input.nextInt();
            ^
Main.java:9: error: illegal start of expression
????????????????????????row = input.nextInt();
             ^
Main.java:9: error: illegal start of expression
????????????????????????row = input.nextInt();
              ^
Main.java:9: error: illegal start of expression
????????????????????????row = input.nextInt();
               ^
Main.java:9: error: illegal start of expression
????????????????????????row = input.nextInt();
                ^
Main.java:9: error: illegal start of expression
????????????????????????row = input.nextInt();
                 ^
Main.java:9: error: illegal start of expression
????????????????????????row = input.nextInt();
                  ^
Main.java:9: error: illegal start of expression
????????????????????????row = input.nextInt();
                   ^
Main.java:9: error: illegal start of expression
????????????????????????row = input.nextInt();
                    ^
Main.java:9: error: illegal start of expression
????????????????????????row = input.nextInt();
                     ^
Main.java:9: error: illegal start of expression
????????????????????????row = input.nextInt();
                      ^
Main.java:9: error: illegal start of expression
????????????????????????row = input.nextInt();
                       ^
Main.java:9: error: : expected
????????????????????????row = input.nextInt();
                                             ^
Main.java:10: error: illegal start of expression
????????????????????????col = input.nextInt();
^
Main.java:10: error: illegal start of expression
????????????????????????col = input.nextInt();
 ^
Main.java:10: error: illegal start of expression
????????????????????????col = input.nextInt();
  ^
Main.java:10: error: illegal start of expression
????????????????????????col = input.nextInt();
   ^
Main.java:10: error: illegal start of expression
????????????????????????col = input.nextInt();
    ^
Main.java:10: error: illegal start of expression
????????????????????????col = input.nextInt();
     ^
Main.java:10: error: illegal start of expression
????????????????????????col = input.nextInt();
      ^
Main.java:10: error: illegal start of expression
????????????????????????col = input.nextInt();
       ^
Main.java:10: error: illegal start of expression
????????????????????????col = input.nextInt();
        ^
Main.java:10: error: illegal start of expression
????????????????????????col = input.nextInt();
         ^
Main.java:10: error: illegal start of expression
????????????????????????col = input.nextInt();
          ^
Main.java:10: error: illegal start of expression
????????????????????????col = input.nextInt();
           ^
Main.java:10: error: illegal start of expression
????????????????????????col = input.nextInt();
            ^
Main.java:10: error: illegal start of expression
????????????????????????col = input.nextInt();
             ^
Main.java:10: error: illegal start of expression
????????????????????????col = input.nextInt();
              ^
Main.java:10: error: illegal start of expression
????????????????????????col = input.nextInt();
               ^
Main.java:10: error: illegal start of expression
????????????????????????col = input.nextInt();
                ^
Main.java:10: error: illegal start of expression
????????????????????????col = input.nextInt();
                 ^
Main.java:10: error: illegal start of expression
????????????????????????col = input.nextInt();
                  ^
Main.java:10: error: illegal start of expression
????????????????????????col = input.nextInt();
                   ^
Main.java:10: error: illegal start of expression
????????????????????????col = input.nextInt();
                    ^
Main.java:10: error: illegal start of expression
????????????????????????col = input.nextInt();
                     ^
Main.java:10: error: illegal start of expression
????????????????????????col = input.nextInt();
                      ^
Main.java:10: error: illegal start of expression
????????????????????????col = input.nextInt();
                       ^
Main.java:10: error: : expected
????????????????????????col = input.nextInt();
                                             ^
Main.java:11: error: illegal start of expression
????????????????????????if (row == 0 && col == 0) {
^
Main.java:11: error: illegal start of expression
????????????????????????if (row == 0 && col == 0) {
 ^
Main.java:11: error: illegal start of expression
????????????????????????if (row == 0 && col == 0) {
  ^
Main.java:11: error: illegal start of expression
????????????????????????if (row == 0 && col == 0) {
   ^
Main.java:11: error: illegal start of expression
????????????????????????if (row == 0 && col == 0) {
    ^
Main.java:11: error: illegal start of expression
????????????????????????if (row == 0 && col == 0) {
     ^
Main.java:11: error: illegal start of expression
????????????????????????if (row == 0 && col == 0) {
      ^
Main.java:11: error: illegal start of expression
????????????????????????if (row == 0 && col == 0) {
       ^
Main.java:11: