Source : https://www.hackerrank.com/challenges/30-loops
Objective
In this challenge, we're going to use loops to help us do some simple math. Check out the Tutorial tab to learn more.
Task
Given an integer, , print its first multiples. Each multiple (where ) should be printed on a new line in the form: n x i = result
.
Input Format
A single integer, .
Constraints
Output Format
Print lines of output; each line (where ) contains the of in the form: n x i = result
.
Sample Input
2
Sample Output
2 x 1 = 22 x 2 = 42 x 3 = 62 x 4 = 82 x 5 = 102 x 6 = 122 x 7 = 142 x 8 = 162 x 9 = 182 x 10 = 20
Source : https://www.hackerrank.com/challenges/30-loops
Solution
// Karthikalapati.blogspot.com | |
import java.util.Scanner; | |
public class Solution { | |
public static void main(String[] args) { | |
Scanner scan = new Scanner(System.in); | |
int multiplier = scan.nextInt(); | |
scan.close(); | |
for (int i = 1; i <= 10; i++) { | |
System.out.format("%d x %d = %d%n", multiplier, i , i * multiplier); | |
} | |
} | |
} |
No comments:
Post a Comment