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.
C programming 3. Write a do-while loop that displays: 0,10,20,30,40 4.Write nested for loops that displays...
C programming 3. Write a do-while loop that displays: 0,10,20,30,40 4.Write nested for loops that displays three rows of asterisks: ***** ***** ***** 5. Write a complete program that reads a set of integers using scant() until a sentinel value of -99 is read. Once that value is read, display the sum of the value read, exclusive of the -99. 6.Write a procedure(function, method named times10() that accepts an integer argument and displays the result of multiplying the argument by...
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
In C++ write a program for a multiplication table It must Prompt the user for two...
In C++ write a program for a multiplication table It must Prompt the user for two integers between 1 and 20 (inclusive) • also must Calculates and displays the multiplication table in a well-formatted output The table must include a label for each row and column The program must follow the requirements: • Validates user input, displaying an error message and prompting to user to enter another integer if the input is invalid, and repeating it as many times as...
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 a Java program that calculates and displays the Fibonacci numbers * First prompt the...
* Write a Java program that calculates and displays the Fibonacci numbers * First prompt the user to input a number, N * Then use a for loop to calculate and display the first N fibonocci numbers * For example, if the user enters 5, the output should be: * 1, 1, 2, 3, 5 * * if the user enters 10, the output should be: * 1, 1, 2, 3, 5, 8, 13, 21, 34, 55
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 C++ program that asks the user to enter in three numbers and displays the...
Write a C++ program that asks the user to enter in three numbers and displays the numbers in ascending order. If the three numbers are all the same the program should tell the user that all the numbers are equal and exits the program. Be sure to think about all the possible cases of three numbers. Be sure to test all possible paths. Sample Runs: NOTE: not all possible runs are shown below. Sample Run 1 Welcome to the order...
Design a program in Java that displays all of the prime numbers from 1 through 100....
Design a program in Java that displays all of the prime numbers from 1 through 100. The program should have a loop that calls the isPrime() function. 11 Prime Numbers List (15 points) Use CONSTANTS to set the maximum number in the table to 100 and the number of entries per row to 5.   Table of prime numbers from 1 to 100 1 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT