Java Exercises: Print multiplication table of a number upto 10
Java Basic: Exercise-7 with Solution
Write a Java program that takes a number as input and prints its multiplication table upto 10.
Test Data:
Input a number: 8
Pictorial Presentation:
Sample Solution:
Java Code:
import java.util.Scanner;
public class Exercise7 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.print("Input a number: ");
int num1 = in.nextInt();
for (int i=0; i< 10; i++){
System.out.println(num1 + " x " + (i+1) + " = " +
(num1 * (i+1)));
}
}
}
Sample Output:
Input a number: 8 8 x 1 = 8 8 x 2 = 16 8 x 3 = 24 8 x 4 = 32 8 x 5 = 40 8 x 6 = 48 8 x 7 = 56 8 x 8 = 64 8 x 9 = 72 8 x 10 = 80
Flowchart:
Sample Solution:
Java Code:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("Input the Number: ");
int n = in .nextInt();
for (int i = 1; i <= 10; i++) {
System.out.println(n + "*" + i + " = " + (n * i));
}
}
}
Sample Output:
Input the Number: 6 6*1 = 6 6*2 = 12 6*3 = 18 6*4 = 24 6*5 = 30 6*6 = 36 6*7 = 42 6*8 = 48 6*9 = 54 6*10 = 60
Flowchart:
Java Code Editor:
Contribute your code and comments through Disqus.
Previous: Write a Java program to print the sum (addition), multiply, subtract, divide and remainder of two numbers.
Next: Write a Java program to display the specified pattern.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
Java: Tips of the Day
How to sort an ArrayList?
Collections.sort(testList); Collections.reverse(testList);
That will do what you want. Remember to import Collections though!
Ref: https://bit.ly/32urdSe
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework