UNB/ CS/ David Bremner/ teaching/ cs1083/ java/ PBM2b.java
import java.util.Scanner;

public class PBM2b {
    private int[][] bits;
    private int rows,columns;
    PBM2b() throws ImageFormatException{
        Scanner sc =
            new Scanner(System.in);
        if (!sc.next().equals("P1"))
            throw new ImageFormatException("Format error");
        columns=sc.nextInt();
        rows=sc.nextInt();
        bits=new int[rows][columns];
        for (int i=0; i< rows; i++){
            String line="";
            while (line.length() < columns) {
                line += sc.next();
            }
            for (int j=0; j<columns; j++)
                bits[i][j]=line.charAt(j)-'0';
        }
    }
    public String toString(){
        String result="";
        for (int i=0; i< rows; i++){
            String row="";
            for (int j=0; j<columns; j++){
                if (bits[i][j]==1)
                    row += "*";
                else
                    row += " ";
            }
            result += row+"\n";
        }
        return result;

    }
    public static void main(String [] args) throws ImageFormatException{


        long startTime = System.nanoTime();
        PBM2b pbm = new PBM2b();
        long readTime = System.nanoTime();
        System.err.println("time to read " + (readTime-startTime)/1e6 + "ms");

        String str = pbm.toString();
        long stringTime = System.nanoTime();
        System.err.println("time to string " + (stringTime-readTime)/1e6 + "ms");

        System.out.println(str);
        long wroteTime = System.nanoTime();
        System.err.println("time to write " + (wroteTime-stringTime)/1e6 + "ms");


    }
}
//@keywords: array, 2D array, bitmap, file, image processing