Java generate multiplication table for given number ?
>> In Java, we can generate multiplication table for given number using for loop, while loop, do-while loop.,.
public class multiplicationTable {
public static void main(String[] args) {
int n = 19;
System.out.println("Multiplication table using for loop");
for (int i = 1; i <= 10; i++) {
System.out.println(n + "*" + i + "=" + (n * i));
}
System.out.println("Multiplication table using for while loop");
int j = 1;
while (j <= 10) {
System.out.println(n + "*" + j + "=" + (n * j));
j++;
}
System.out.println("Multiplication table using for do-while loop");
int k = 1;
do {
System.out.println(n + "*" + k + "=" + (n * k));
k++;
} while (k <= 10);
}
}
Output:
Please comment below to feedback or ask questions.
No comments:
Post a Comment
Please comment below to feedback or ask questions.