Problem
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 = 2
2 x 2 = 4
2 x 3 = 6
2 x 4 = 8
2 x 5 = 10
2 x 6 = 12
2 x 7 = 14
2 x 8 = 16
2 x 9 = 18
2 x 10 = 20
How I solved the problem
# 단순 반복문 문제. output처럼 나오도록 println에서 맞춰주는것도 중요!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | import java.io.*; import java.math.*; import java.security.*; import java.text.*; import java.util.*; import java.util.concurrent.*; import java.util.regex.*; public class Solution { private static final Scanner scanner = new Scanner(System.in); public static void main(String[] args) { int n = scanner.nextInt(); scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?"); int loop = 10; for (int i = 0; i < loop; i++) { int multiple = i + 1; System.out.println(n + " x " + multiple + " = " + (n * multiple)); } scanner.close(); } } | cs |
[출처 : https://www.hackerrank.com ]
'1 Day 1 Algorithms' 카테고리의 다른 글
[2018.12.17] Plus Minus (0) | 2018.12.17 |
---|---|
[2018.12.17] Let's Review (0) | 2018.12.17 |
[2018.12.15] Class vs. Instance (0) | 2018.12.17 |
[2018.12.14] A Very Big Sum (0) | 2018.12.14 |
[2018.12.13] Counting Valleys (0) | 2018.12.14 |
댓글