Search⌘ K

Solution Review: Multiplication Table of a Number

Explore how to use the while loop in Java to calculate and print the multiplication table of a given number from 1 to 10. This lesson guides you through initializing variables, iterating correctly, and updating values within the loop to produce accurate results.

We'll cover the following...

Solution #

Java
class MultiplicationTable {
public static String test(int num) {
int i = 1;
String answer = "";
int table;
while (i <= 10) {
table = num * i;
answer += String.valueOf(table) + " ";
i++;
}
return answer;
}
public static void main( String args[] ) {
System.out.println(test(5));
}
}

Explanation

To calculate the table of the given number, we will multiply the given number with 1 ...