0% found this document useful (0 votes)
65 views3 pages

Addition Table Generator in Java

This Java class calculates and prints an addition table with user-defined rows and columns. It prompts the user to enter the number of rows from 2 to 30 and the number of columns from 2 to 12. It then prints the addition table with row and column headings.

Uploaded by

Vrinda Dhongle
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
65 views3 pages

Addition Table Generator in Java

This Java class calculates and prints an addition table with user-defined rows and columns. It prompts the user to enter the number of rows from 2 to 30 and the number of columns from 2 to 12. It then prints the addition table with row and column headings.

Uploaded by

Vrinda Dhongle
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd

//[Link] //This class calculates and prints an addition table.

//Class methods: // GetRows // Prompt the user to enter the number of rows in their addition table. // This value should be chosen from 2 to 30, and if the user enters a value // outside of this range, they should be prompted again. // GetColumns // Prompt the user to enter the number of columns in their addition table. // This value should be chosen from 2 to 12, and if the user enters a value // outside of this range, they should be prompted again. // PrintAddTable // Print out the addition table with the user-defined number of rows and // columns. Your table should have row and column headings. //Class variables: // row - The number of rows for the addition table. // column - The number of columns for the addition table. import [Link]; public class Add { private int row; // The number of rows for the addition table. private int column; // The number of columns for the addition table. private Scanner kb = new Scanner([Link]); public Add() { row = column = 0; } public void GetRows()

{ [Link]("Enter the number of rows to be shown ( 2 - 30 ) ->\t"); row = [Link](); if (!(row >= 2 && row <= 30)) { GetRows(); return; } } public void GetColumns() { [Link]("Enter the number of columns to be shown ( 2 - 12 ) ->\t"); column = [Link](); if (!(column >= 2 && column <= 12)) { GetColumns(); return; } } public void PrintAddTable() { [Link]("\nHere is your table:\n"); [Link]("\t|\t"); int curCol = 1; while (curCol <= column) { [Link]("%-8d", curCol); curCol++; } [Link](); int currDash = 1; do {

[Link]('-'); currDash++; } while (currDash <= (column + 2) * 8 - 6); [Link](); for (int r = 1; r <= row; r++) { [Link]("%-8d|\t", r); for (int c = 1; c <= column; c++) { [Link]("%-8d", c + r); } [Link](); } [Link](); } public static void main(String[] args) { Add table = new Add(); [Link](); [Link](); [Link](); } }

You might also like