IT/Programming / / 2023. 4. 17. 10:27

[HackerRank] Day 5: 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, n, print its first 10 multiples. Each multiple n x i(where 1 <= i <= 10) should be printed on a new line in the form: n x i = result.

 

Input Format

A single integer, n.

 

Constraints

2 <= n <=20

 

Output Format

Print 10 lines of output; each line i (where 1 <= i <=10) contains the result of n x i 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
 

 

import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Solution {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int i = 1;
        for(;i <= 10;i++) {
        	System.out.println(n+" x "+i+" = "+(i*n));
        }
    }
}
 
www.hackerrank.com

 

 

반응형

'IT > Programming' 카테고리의 다른 글

[HackerRank] Day 7: Arrays  (0) 2023.04.17
[HackerRank] Day 6: Let's Review  (0) 2023.04.17
[HackerRank] Day 4: Class vs. Instance  (0) 2023.04.17
[HackerRank] Day 3: Intro to Conditional Statements  (0) 2023.04.17
[HackerRank] Day 2: Operators  (0) 2023.04.17
  • 네이버 블로그 공유
  • 네이버 밴드 공유
  • 페이스북 공유
  • 카카오스토리 공유