Table of a Number

Dear Sciaku Learner you are not logged in or not enrolled in this course.

Please Click on login or enroll now button.

If you have any query feel free to chat us!

Happy Coding! Happy Learning!

Lecture 29:- Table of a Number

To generate the table (multiplication) of a given number in Java, you can use a loop to calculate the product of the number with integers from 1 to a specified range (usually 10). Here's a Java program to display the table of a given number:

javaCopy code
import java.util.Scanner; public class NumberTable { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("Enter a number to generate its table: "); int number = scanner.nextInt(); // Display the table of the given number System.out.println("Table of " + number + ":"); for (int i = 1; i <= 10; i++) { int product = number * i; System.out.println(number + " x " + i + " = " + product); } scanner.close(); } }

Example output:

cssCopy code
Enter a number to generate its table: 5 Table of 5: 5 x 1 = 5 5 x 2 = 10 5 x 3 = 15 5 x 4 = 20 5 x 5 = 25 5 x 6 = 30 5 x 7 = 35 5 x 8 = 40 5 x 9 = 45 5 x 10 = 50

In the program above, we take the user input for the number and store it in the variable number. We then use a for loop to iterate from 1 to 10. Inside the loop, we calculate the product of the number with the current iterator value (i) and print the table entries in the specified format.

You can adjust the loop range to generate tables of different sizes or modify the program to take the range as user input if you want more flexibility.

 

Disclaimer:-

Under Section 107 of the copyright act 1976, allowance is made for fair use for purposes such as criticism, comment, news reporting, scholarship, and research. Fair use is a use permitted by copyright statute that might otherwise be infringing. Non-profit, educational, or personal use tips the balance in favor of fair use.

 

6. Loops

Comments: 0

Frequently Asked Questions (FAQs)

How do I register on Sciaku.com?
How can I enroll in a course on Sciaku.com?
Are there free courses available on Sciaku.com?
How do I purchase a paid course on Sciaku.com?
What payment methods are accepted on Sciaku.com?
How will I access the course content after purchasing a course?
How long do I have access to a purchased course on Sciaku.com?
How do I contact the admin for assistance or support?
Can I get a refund for a course I've purchased?
How does the admin grant access to a course after payment?