/** * Nested loop demo * Print a table containing the values of the loop counter variables * @author Pete Nordquist * @version 100120 */ public class W03N02 { public static void main( String[] args) { // declare variables int rows; int cols; int rowCnt = 0; int colCnt = 0; System.out.print("How many rows> "); rows = TextIO.getlnInt(); System.out.print("How many columns> "); cols = TextIO.getlnInt(); // loop over rows while (rowCnt < rows) { // must reinitialize colCnt everytime through the row loop colCnt = 0; // loop over cols while (colCnt < cols) { // print the value for this row , col and a tab System.out.print(rowCnt + "," + colCnt + "\t"); // increment the column count colCnt = colCnt + 1; } // print an end of line to end the row System.out.println(); // increment rowCnt rowCnt = rowCnt + 1; } } }