Question

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 calculation between number times table-number. The process will repeat 20 times or 20 rows.

Use printf to format the output.

Example of how the input and output should look like:

Enter a times table number: 7

Number           Times           Table   Equals         Result

1                      X                     7          =                      7

2                      X                     7          =                      14

3                      X                     7          =                      21

.

.

  1.             X                     7          =                      140

Use the flowchart below to write the Java Program that generates the Times Table. (Test the flowchart or the pseudo code for accuracy before writing Java Code)

  1. Write the JAVA program
  2. Compile for errors
  3. Execute/Run
  4. Print the program and print the output
  5. Submit Program and Output

Homework Answers

Answer #1

Java program that generates the times table.

Step-1: Read the integer whose table we need to print

Step-2: Use for loop to iterate and print the table from i=1 to i<=20 because we need the table to be printed till 20. Here we are asked to use printf statement to format the output. The printf() function allows the programmer to print multiple objects at the same time.The syntax to use the printf statemement is shown below:

Syntax: System.out.printf(format, args);

The format parameter specifies the formatting rules that begin with % and the args is the arguments referenced by the format specifiers in the format string. The format specifiers %d prints an integer, %c prints a character, %s prints a string.

Note: Please refer to the screenshot of the code to understand the indentation of the code. Also the code is explained in the screenshot.

Java Code:

import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
int i, n;
Scanner s = new Scanner(System.in);
   System.out.print("Enter a times table number:");
   n=s.nextInt();
   System.out.println("Number Times Table Equals Result");
for(i=1; i <= 20; i++)
{
System.out.printf( "%d \t %c \t %d \t %c \t %d \n",i,'x',n,'=',i*n);

}
}
}

The complete program along with the explaination and output is shown below:

Output-1:

Output-2:

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
In JAVA: Write a program that reads an integer, a list of words, and a character....
In JAVA: Write a program that reads an integer, a list of words, and a character. The integer signifies how many words are in the list. The output of the program is every word in the list that contains the character at least once. Assume at least one word in the list will contain the given character. Assume that the list of words will always contain fewer than 20 words. Ex: If the input is: 4 hello zoo sleep drizzle...
Java Program : Please save the program with the name ‘Dstring.java’ Write a program that reads...
Java Program : Please save the program with the name ‘Dstring.java’ Write a program that reads a string from the keyboard. If the length of the string is an even number, your program should split the string into two strings of equal length. If the length of the string is odd, your program should split the string into two strings where the first part has one more character than the second part. Your program should output the two strings it...
Write spim program and execute it on mars. Your program reads two integer values x and...
Write spim program and execute it on mars. Your program reads two integer values x and y. Write a function called sum that gets x and y passed as parameters and return the sum of odd values between x and y inclusive. In addition write another function called even that gets x and y as parameters and returns the count of all even numbers between x and y inclusive. Also in main print the quotient and remainder of diving y...
Write a Java Program, that opens the file "students.txt" The program must read the file line...
Write a Java Program, that opens the file "students.txt" The program must read the file line by line The program parses each line that it reads For example, for this line: 1:mohamed:ali:0504123456:cs102:cs202 The program must print    >ID = 1    >First Name = Mohamed   >Last Name = Ali   >Mobie = 0504123456   >Courses = cs102, cs202 In addition, it adds the mobile phone number into an ArrayList called studentPhoneList Print the content and the size of studentPhoneList Show your results and provide...
Please write a program that reads the file you specify and calculates how many times each...
Please write a program that reads the file you specify and calculates how many times each word stored in the file appears. However, ignore non-alphabetic words and convert uppercase letters to lowercase letters. For example, all's, Alls, alls are considered to be the same words. What is the output of the Python program when the input file is specified as "proverbs.txt"? That is, in your answer, include the source codes of your word counter program and its output. <proverbs.txt> All's...
java 8.1: Frequency Design and implement an application that reads an arbitrary number of integers that...
java 8.1: Frequency Design and implement an application that reads an arbitrary number of integers that are in the range 0 to 50 inclusive and counts how many occurrences of each are entered. After all input has been processed, print all of the values (with the number of occurrences) that were entered one or more times. The output should be one frequency count per line with the following format: 3 occurrences of 2 7 occurrences of 5 SPECIFICATION OF NAMES:...
Write a program in java that generates a two-column table showing Fahrenheit temperatures from -40F to...
Write a program in java that generates a two-column table showing Fahrenheit temperatures from -40F to 120F and their equivalent Celsius temperatures. Each line in the table should be 5 degrees F more than the previous one. Both the Fahrenheit and Celsius temperatures should be accurate to 1 decimal place. I am not able to use: import java.text.DecimalFormat; Any feedback would be helpful.
Write code in JAVA Write a program that will output a right triangle based on user...
Write code in JAVA Write a program that will output a right triangle based on user specified input height (int) and specified input symbol (char).The first line will have one user-specified character, such as % or *. Each subsequent line will have one additional user-specified character until the number in the triangle's base reaches specified input height. Output a space after each user-specified character, including after the line's last user-specified character. Hint: Use a nested for loop. Ex:If the input...
You are required to write a program in JAVA based on the problem description given. Read...
You are required to write a program in JAVA based on the problem description given. Read the problem description and write a complete program with necessary useful comment for good documentation. Compile and execute the program. ASSIGNMENT OBJECTIVES: • To introduce queue data structure. DESCRIPTIONS OF PROBLEM: Exercise : Write a program to reverse element of a stack. For any given word (from input), insert every character (from the word) into a stack. The output from the stack should be...
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:
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT