write a program in Java to print the table of a given number
Answers
Explanation:
JavaScript Code Snippet - Function to Print Table of an Entered Number
JavaScript function
<script type="text/javascript">
function printTable(){
var num;
num=Number(document.getElementById('txtNumber').value);
for(var i=1; i<=10; i++){
var pTag= document.getElementById('pPrint');
pTag.innerHTML += (num*i) + "<br/>"
}
}
</script>
HTML Source Code with JavaScript
<!--JavaScript - Function to Display Table of an entered Number.-->
<html>
<head>
<title>JavaScript - Function to Display Table of an entered Number.</title>
<script type="text/javascript">
function printTable(){
var num;
num=Number(document.getElementById('txtNumber').value);
for(var i=1; i<=10; i++){
var pTag= document.getElementById('pPrint');
pTag.innerHTML += (num*i) + "<br/>"
}
}
</script>
</head>
<body style="text-align: center;">
<h1>JavaScript - Function to Display Table of an entered Number.</h1>
<p><input type="text" id="txtNumber" placeholder="Enter number"/></p>
<p><input type="button" value="Print Table." onclick='printTable()'/>
<!--print numbers-->
<p id="pPrint"></p>
</body>
</html>
Result
import java.util.Scanner;
class MultiplicationTable
{
public static void main(String args[])
{
int n, c;
System.out.println("Enter an integer to print it's multiplication table");
Scanner in = new Scanner(System.in);
n = in.nextInt();
System.out.println("Multiplication table of " + n);
for (c = 1; c <= 10; c++)
System.out.println(n + "*" + c + " = " + (n*c));
}
}