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
Write a program that reads in a table of numbers and finds out the average of...
Write a program that reads in a table of numbers and finds out the average of each row and column. This program should first take two numbers as number of rows and columns as input from the user.
Write a java program that reads two sentences as strings, the program should print the common...
Write a java program that reads two sentences as strings, the program should print the common terms in both sentences example: input: I did my java homework yesterday yesterday i went to java island
Write a program that reads three integer values from the keyboard using the Scanner class representing,...
Write a program that reads three integer values from the keyboard using the Scanner class representing, respectively, a number of quarters, dimes, and nickels. Convert the total coin amount to dollars and output the result.Write a program that reads three integer values from the keyboard using the Scanner class representing, respectively, a number of quarters, dimes, and nickels. Convert the total coin amount to dollars and output the result.
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...
Write a program that reads three integer values from the keyboard using the Scanner class representing,...
Write a program that reads three integer values from the keyboard using the Scanner class representing, respectively, a number of quarters, dimes, and nickels. Convert the total coin amount to dollars and output the result.
JAVA PROGRAMMING: Write a program called TimeSymbolTables that creates three symbol tables, each of a different...
JAVA PROGRAMMING: Write a program called TimeSymbolTables that creates three symbol tables, each of a different implementation. Each symbol table will contain as a key a word read from a text file and as a value the number of times that word occurs in the text file. Have the program fill the first symbol table with these counts, keeping track of how long that takes using a Stopwatch object. It then does the same thing with the second symbol table....
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...
Perl language and by using VS Code: Write a program that reads a number, adds up...
Perl language and by using VS Code: Write a program that reads a number, adds up the cube of all the digits, and displays the result. Run your code with the following test number: 1242 It should give 81. Please include screenshots of your outputs.
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...