Question

(SubtractionTable.java) Write a program that displays the following subtraction table. Notes: You must use a nested...

  1. (SubtractionTable.java) Write a program that displays the following subtraction table.

Notes: You must use a nested loop. There are spaces at the beginning of each row.

                                                                                                                2 - 1 = 1  

                                                                                                3 - 1 = 2   3 - 2 = 1  

                                                                                4 - 1 = 3   4 - 2 = 2   4 - 3 = 1  

                                                                5 - 1 = 4   5 - 2 = 3   5 - 3 = 2   5 - 4 = 1  

                                                6 - 1 = 5   6 - 2 = 4   6 - 3 = 3   6 - 4 = 2   6 - 5 = 1  

                                7 - 1 = 6   7 - 2 = 5   7 - 3 = 4   7 - 4 = 3   7 - 5 = 2   7 - 6 = 1  

                8 - 1 = 7   8 - 2 = 6   8 - 3 = 5   8 - 4 = 4   8 - 5 = 3   8 - 6 = 2   8 - 7 = 1  

9 - 1 = 8   9 - 2 = 7   9 - 3 = 6   9 - 4 = 5   9 - 5 = 4   9 - 6 = 3   9 - 7 = 2   9 - 8 = 1

Homework Answers

Answer #1

//Create class SubstractionTable.java

public class SubstractionTable {
void printSubstractionTable()
{
//nested loop to display substraction table
int rows=10;
for(int i=2;i<rows;i++)
{
for (int j =1; j < rows-i; j++) {
System.out.print(" ");
}
for(int j=1;j<i;j++)
{
   System.out.print(i+"-"+j+"="+(i-j)+" ");//print the table
}
System.out.println(" ");//new line after completion of inner loop
}
}
public static void main(String[] args) {
SubstractionTable sc=new SubstractionTable();
sc.printSubstractionTable();
}
}
__________________________________________OUTPUT_________________________________________

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
(AdditionTable.java) Write a program that displays the following addition table. Notes: You must use a nested...
(AdditionTable.java) Write a program that displays the following addition table. Notes: You must use a nested loop. There are spaces at the beginning of each row.
Question: Write a C++ program to ask the user to give you the number of rows...
Question: Write a C++ program to ask the user to give you the number of rows and number of columns, then make the multiplication table by using nested loop. For example, if the user enters 3 for rows and 4 for columns then the multiplication table would be like the following: 1    2   3     4 1   1 2 3 4 2   2    4      6    8 3    3 6 9 12
C++ Code! Represent the following matrix using a two-dimensional array and write a nested for loop...
C++ Code! Represent the following matrix using a two-dimensional array and write a nested for loop to initialize the elements (do not initialize the array in the declaration): 10  9   8 7   6   5 4 3   2
write a Nested loop in C# to print out the following output using windows form. 0...
write a Nested loop in C# to print out the following output using windows form. 0 0 1 0 2 4 0 3 6 9 0 4 8 16 32
write Java code FAMOUS QUOTES PROGRAM - Write a program that displays the following information in...
write Java code FAMOUS QUOTES PROGRAM - Write a program that displays the following information in the EXACT pattern/formatting shown below. You must use escape sequences to do this - this is not English class and things are written below to test you on escape sequences form class, so no matter what follow the pattern/formatting shown (the dashes and spaces do not have to be perfect but everything else should match, you should try to use tabs for the spacing...
Write a Java program using a single multi-level nested for-loop to display the following pattern (For...
Write a Java program using a single multi-level nested for-loop to display the following pattern (For each iteration, only one character can be printed) : 1,2,3,4,5,6,7,8,9#1,2,3,4,5,6,7,8,9#1,2,3,4,5,6,7,8,9# 3,6,9,12,15,18,21,24,27#3,6,9,12,15,18,21,24,27#3,6,9,12,15,18,21,24,27# 5,10,15,20,25,30,35,40,45#5,10,15,20,25,30,35,40,45#5,10,15,20,25,30,35,40,45#
given an integer, write a program in C++ that displays the number as follows first line        ...
given an integer, write a program in C++ that displays the number as follows first line         all digits second line   all except first digit ... last line          last digit ex) 5 6 7 8 6 7 8 7 8 8
Write a Java program to print the result of the following operations. Your program should contain...
Write a Java program to print the result of the following operations. Your program should contain 4 methods (for each of given data sets). Yes, methods here are not structurally necessary, this requirement is only for you to get practice writing methods. Test Data: a. -8 + 4.0 * 6 b. (11+9) % 9 c. 20 + (-3)*3.0 / 8 d. 5 + 14 / 3 * 2 - 7 % 3 Your program:
In Java. Write a program that reads-in a times table-number. The program, using this table-number will...
In Java. Write a program that reads-in a times table-number. The program, using this table-number will produce the following report (as shown). The first item in the report is a number with starting value 1. Second column is the word “ X ” (representing the times symbol). Third column is the table-number (itself). Following is an equal sign “ = “ (representing a result). Last column is the result of the operation for that line or row which is the...
given an integer, write a program that displays the number as follows first line         all digits...
given an integer, write a program that displays the number as follows first line         all digits second line   all except first digit third line        all except first two digits ..... last line          the last digit ex) 5 6 7 8 6 7 8 7 8 8
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT