1.

import java.util.Scanner;

/**
* Angewandte Mathematik, SS11
* Problem: 10189 - Minesweeper
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=13&page=show_problem&problem=1130
*
* @author Benedikt Z¨nnchen
* @author Erik Wenzel
* @version 1.0, 03/27/2011
*
* Method : Ad-Hoc
* Status : Accepted
* Runtime: 0.508
*/

public class Main
{

public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int rows;
int cols;
int[][] field;
int counter = 1;
//char currentChar;
String currentLine = "";
//System.out.println(sc.next());
while((rows = sc.nextInt()) != 0 && (cols = sc.nextInt()) != 0)
{
field = new int[rows][cols];

for(int i=0; i<rows; i++)
{
currentLine = sc.next();
for(int j=0; j<cols; j++)
{
if(currentLine.charAt(j)=='*')
{
field[i][j] = -9;
if(i>0)
{
field[i-1][j]++;
if(j>0)
{
field[i-1][j-1]++;
}

if(j<cols-1)
{
field[i-1][j+1]++;
}
}

if(i<rows-1)
{
field[i+1][j]++;
if(j>0)
{
field[i+1][j-1]++;
}

if(j<cols-1)
{
field[i+1][j+1]++;
}
}

if(j>0)
{
field[i][j-1]++;
}

if(j<cols-1)
{
field[i][j+1]++;
}
}
}
}

// Ausgabe
if(counter >1)
{
System.out.println();
}
System.out.println("Field #"+counter+":");
for(int i=0; i<rows; i++)
{
for(int j=0; j<cols; j++)
{
if(field[i][j]<0)
{
System.out.print("*");
}
else
{
System.out.print(field[i][j]);
}
}
System.out.println();
}
counter++;
}
}

}

2.

/**
* Angewandte Mathematik, SS11
* Problem: 10189 Minesweeper
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=13&page=show_problem&problem=1130
*
* @author Unverzart Michael
* @author Wurth Manuel
* @version 1.0, 26/3/2011
*
* Method : Ad-Hoc
* Status : Accepted
* Runtime: 0.432
*/

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

public static void main(String[] args) throws Exception{
int rows=0;
int cols=0;
int count=1;

BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String inputLine;

while(true)
{
inputLine = reader.readLine();
if(inputLine==null) throw new Exception();
StringTokenizer st = new StringTokenizer(inputLine);
rows = new Integer(st.nextToken());
cols = new Integer(st.nextToken());
if(rows==0||cols==0) break;
if(rows<0||rows>100||cols<0||cols>100) throw new Exception();

int[][] array = new int[rows][cols];

for(int i=0 ; i<rows ; i++)
{
inputLine = reader.readLine();
char[] chararray = inputLine.toCharArray();
for(int j=0 ; j<cols ; j++)
{
if(chararray[j]=='*') {array[i][j]=-1; }//if mine -> mark field with -1
else
{
if(chararray[j]!='.') throw new Exception();
array[i][j]=0; //else -> 0
}
}
}

//mine searching in surrounding area of 0-fields
for(int i=0 ; i<rows ; i++)
{
for(int j=0 ; j<cols ; j++)
{
if(array[i][j]==0)
{
if(i-1>=0){ if(array[i-1][j]==-1)array[i][j]++; } //up
if(j-1>=0){ if(array[i][j-1]==-1)array[i][j]++; } //left
if(i+1<rows){ if(array[i+1][j]==-1)array[i][j]++; } //down
if(j+1<cols){ if(array[i][j+1]==-1)array[i][j]++; } //right
if(i-1>=0 && j-1>=0){ if(array[i-1][j-1]==-1)array[i][j]++; } //left up
if(i-1>=0 && j+1<cols){ if(array[i-1][j+1]==-1)array[i][j]++; } //right up
if(i+1<rows && j-1>=0){ if(array[i+1][j-1]==-1)array[i][j]++; } //left down
if(i+1<rows && j+1<cols){ if(array[i+1][j+1]==-1)array[i][j]++; } //right down
}
}
}

//output

if(count >1)
{
System.out.println();
}
System.out.println("Field #"+count+":");
for(int i=0 ; i<rows ; i++)
{
for(int j=0 ; j<cols ; j++)
{
if(array[i][j]==-1)System.out.print("*");
else System.out.print(array[i][j]);
}
System.out.print("\n");
}
count++;
rows = cols = 0;
}
}
}



--------------------------------------------------------------------------------------------------------------------

1.

/**
* FWP, Ausgewählte Probleme aus dem ACM Programming Contest, WS10/11
* Problem: 10189 - Minesweeper
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=13&page=show_problem&problem=1130
*
* @author Manuel Hager
* @version 1.0, 10/11/2010
*
* Method : Ad-Hoc
* Status : Accepted
* Runtime: 0.532
*/

import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;


public class Main
{
private static List<char[][]> fields = new ArrayList<char[][]>();

private static int[] combination = new int[] { -1, 0, 1 };

private static void run(BufferedReader reader) throws Exception
{
while(true)
{
String line = reader.readLine();

String[] parts = line.split(" ");

int rows = Integer.parseInt(parts[0]);
int cols = Integer.parseInt(parts[1]);

if(rows == 0 && cols == 0) {
return;
}

char[][] field = new char[rows][cols];
for(int currRow = 0; currRow < rows; currRow++) {
line = reader.readLine();
for(int currCol = 0; currCol < cols; currCol++) {
field[currRow][currCol] = line.charAt(currCol);
}
}

fields.add(field);
}
}

private static void calc()
{
for(char[][] currField : fields)
{
for(int currRow = 0; currRow < currField.length; currRow++) {
for(int currCol = 0; currCol < currField[currRow].length; currCol++){
if(currField[currRow][currCol] == '.') {
currField[currRow][currCol] = getNumber(currField, currRow, currCol);
}
}
}
}
}

private static char getNumber(char[][] field, int row, int col)
{
int count = 0;

for(int r : combination)
{
for(int c: combination)
{
if(isOkay(field, row + r, col + c))
{
if(field[row + r][col + c] == '*') {
count++;
}
}
}
}

return Character.forDigit(count, 10);
}

private static boolean isOkay(char[][] field, int row, int col)
{
if(row < 0 || col < 0)
return false;

if(row >= field.length)
return false;

if(col >= field[0].length)
return false;

return true;
}

public static void main(String[] args)
{
try
{
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

run(reader);

reader.close();
}
catch(Exception ex)
{}

calc();

//******************************
//Ausgabe!
int count = 1;
for(char[][] currField : fields)
{
System.out.printf("Field #%d:%n", count++);

for(int currRow = 0; currRow < currField.length; currRow++) {
for(int currCol = 0; currCol < currField[currRow].length; currCol++){
System.out.print(currField[currRow][currCol]);
}
System.out.println();
}

//Ende? kein lineFeed notwendig.
if(fields.size() + 1 != count) {
System.out.println();
}
}
}
}