Language: Java

import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main {
	static int w,h;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true){
			w=sc.nextInt();
			h=sc.nextInt();
			if(w==0&&h==0) break;
			int[][] map = new int[h][w];
			for(int j=0;j<h;++j){
				for(int i=0;i<w;++i){
					map[j][i]=sc.nextInt();
				}
			}
			int count=0;
			Queue<Node> queue = new LinkedList<Node>();
			for(int j=0;j<h;++j){
				for(int i=0;i<w;++i){
					if(map[j][i]==1){
						queue.add(new Node(j,i)); map[j][i]=0;
						while(!queue.isEmpty()){
							Node cur = queue.remove();
							if(cur.w!=0){
								if(map[cur.h][cur.w-1]==1){
									map[cur.h][cur.w-1]=0; queue.add(new Node(cur.h,cur.w-1));
								}
							}
							if(cur.h!=0){
								if(map[cur.h-1][cur.w]==1){
									map[cur.h-1][cur.w]=0; queue.add(new Node(cur.h-1,cur.w));
								}
							}
							if(cur.w!=w-1){
								if(map[cur.h][cur.w+1]==1){
									map[cur.h][cur.w+1]=0; queue.add(new Node(cur.h,cur.w+1));
								}
							}
							if(cur.h!=h-1){
								if(map[cur.h+1][cur.w]==1){
									map[cur.h+1][cur.w]=0; queue.add(new Node(cur.h+1,cur.w));
								}
							}
							if(cur.w!=0&&cur.h!=0){
								if(map[cur.h-1][cur.w-1]==1){
									map[cur.h-1][cur.w-1]=0; queue.add(new Node(cur.h-1,cur.w-1));
								}
							}
							if(cur.w!=0&&cur.h!=h-1){
								if(map[cur.h+1][cur.w-1]==1){
									map[cur.h+1][cur.w-1]=0; queue.add(new Node(cur.h-1,cur.w+1));
								}
							}
							if(cur.w!=w-1&&cur.h!=0){
								if(map[cur.h-1][cur.w+1]==1){
									map[cur.h-1][cur.w+1]=0; queue.add(new Node(cur.h+1,cur.w-1));
								}
							}
							if(cur.w!=w-1&&cur.h!=h-1){
								if(map[cur.h+1][cur.w+1]==1){
									map[cur.h+1][cur.w+1]=0; queue.add(new Node(cur.h+1,cur.w+1));
								}
							}
						}
						count++;
					}
				}
			}
			System.out.println(count);
		}
	}
}


Compiler output:
Main.java:20: error: cannot find symbol
			Queue<Node> queue = new LinkedList<Node>();
			      ^
  symbol:   class Node
  location: class Main
Main.java:20: error: cannot find symbol
			Queue<Node> queue = new LinkedList<Node>();
			                                   ^
  symbol:   class Node
  location: class Main
Main.java:24: error: cannot find symbol
						queue.add(new Node(j,i)); map[j][i]=0;
						              ^
  symbol:   class Node
  location: class Main
Main.java:26: error: cannot find symbol
							Node cur = queue.remove();
							^
  symbol:   class Node
  location: class Main
Main.java:29: error: cannot find symbol
									map[cur.h][cur.w-1]=0; queue.add(new Node(cur.h,cur.w-1));
									                                     ^
  symbol:   class Node
  location: class Main
Main.java:34: error: cannot find symbol
									map[cur.h-1][cur.w]=0; queue.add(new Node(cur.h-1,cur.w));
									                                     ^
  symbol:   class Node
  location: class Main
Main.java:39: error: cannot find symbol
									map[cur.h][cur.w+1]=0; queue.add(new Node(cur.h,cur.w+1));
									                                     ^
  symbol:   class Node
  location: class Main
Main.java:44: error: cannot find symbol
									map[cur.h+1][cur.w]=0; queue.add(new Node(cur.h+1,cur.w));
									                                     ^
  symbol:   class Node
  location: class Main
Main.java:49: error: cannot find symbol
									map[cur.h-1][cur.w-1]=0; queue.add(new Node(cur.h-1,cur.w-1));
									                                       ^
  symbol:   class Node
  location: class Main
Main.java:54: error: cannot find symbol
									map[cur.h+1][cur.w-1]=0; queue.add(new Node(cur.h-1,cur.w+1));
									                                       ^
  symbol:   class Node
  location: class Main
Main.java:59: error: cannot find symbol
									map[cur.h-1][cur.w+1]=0; queue.add(new Node(cur.h+1,cur.w-1));
									                                       ^
  symbol:   class Node
  location: class Main
Main.java:64: error: cannot find symbol
									map[cur.h+1][cur.w+1]=0; queue.add(new Node(cur.h+1,cur.w+1));
									                                       ^
  symbol:   class Node
  location: class Main
12 errors