//The following three lines are needed to get a number from the keyboard. import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class SpreadSheet { /** * @param args */ public static void main(String[] args) { System.out.print("How many rows? "); final int nrows = getInt(); System.out.print("How many columns? "); final int ncols = getInt(); double[][] a = new double[nrows][ncols]; System.out.println("Please type first column"); for (int row = 0; row < nrows; ++row) { System.out.print("a[" + row + "][0] "); a[row][0] = getInt(); } System.out.println(); for (int row = 0; row < nrows; ++row) { a[row][1] = 2 * a[row][0]; a[row][2] = 10 + a[row][0]; a[row][3] = a[row][1] + a[row][2]; } for (int row = 0; row < nrows; ++row) { for (int col = 0; col < ncols; ++col) { System.out.print(a[row][col] + "\t"); } System.out.println(); } } //The following 16 lines are needed to get a number from the keyboard. private static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); private static int getInt() { try { return Integer.parseInt(reader.readLine()); } catch (IOException e) { System.err.println("Couldn't receive input: " + e.getMessage()); } catch (NumberFormatException e) { System.err.println(e.getMessage() + ", the characters were not a number."); } return 0; } }