Instructions: Answer the following questions one at a time. After answering each question, check your answer (by clicking on the check-mark icon if it is available) before proceeding to the next question.
Getting Ready: Before going any further, you should:
int column, row, sum;
JMUConsole.open();
// Print an addition table
//
for (row=0; row<5; row++)
{
for (column=0; column<5; column++)
{
sum = row + column;
JMUConsole.printf(" %2d ", sum);
}
JMUConsole.printf("\n");
}
JMUConsole.close();
Review this code fragment and make sure you understand it.
AdditionTable that includes
this fragment in main().
AdditionTable.
AdditionTable so that the size of the table
can be changed. Specifically, modify it so that the user can set
the size of the table (which will always be square) by passing
main() a command-line argument. You may assume that
the size will always be less than 15. If no command-line argument is given,
the table must be of size 10.
AdditionTable so that it can
be used to generate an addition table that is formatted as
follows:
+ | 0 1 2 3 4
------------------------
0 | 0 1 2 3 4
1 | 1 2 3 4 5
2 | 2 3 4 5 6
3 | 3 4 5 6 7
4 | 4 5 6 7 8
Suggestion: Do not work on the whole problem at once. First write the loop that will print the column headers. Then modify the nested loops that will print the body of the table.
do-while loops.
AndTable that
can be used to generate a "truth table"
for the && operator that is formatted as follows:
true false
false false
Your solution must use nested do-while loops. (Hint: Think
carefully about the initialization and update
statements in the do-while loop.)
&& | true false
----------------------
true | true false
false | false false
Again, your solution must use only do-while loops.
if statements inside of loops.
AndTable to LogicalOpTable
and modify the code appropriately.
LogicalOpTable so that it can be passed
a String representation of an operator
(i.e., "&&" or "||")
to use and will generate the appropriate "truth table"
for that operator.
Your solution must again use nested do-while loops.
(Hint: Recall that the Text class has a
charAt() function that is passed a String
and an int and returns the char that
is in that String at that position. For example,
Text.charAt("CS", 0) will return 'C'.)
Note: This part of the lab allows you to "go further" on this material. It is neither required nor for extra credit. It will, however, help you gain a deeper understanding of the material.while loops instead of for loops.
while loops instead of do-while loops.
Copyright 2020