티스토리 뷰
HackerRank
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | import java.util.*; import java.io.*; class Solution { public static void main(String[] argh) { Scanner in = new Scanner(System.in); int t = in.nextInt(); for (int i = 0; i < t; i++) { int a = in.nextInt(); int b = in.nextInt(); int n = in.nextInt(); for (int j = 0; j < n; j++) { a = a + (int) Math.pow(2, j) * b; System.out.print(a + " "); } System.out.println(""); } in.close(); } } | cs |
Java Math
Method |
Description |
Math.max(x,y) |
주어진 숫자에서 가장 높은 숫자(highest value) 반환 |
Math.min(x,y) |
가장 낮은 숫자(lowest value) 반환 |
Math.abs(x) |
숫자의 절대값(absolute value) 반환 |
Math.pow(x,y) |
x(base) y(exponent)번 곱한 결과 |
for (int j = 0; j < n; j++) {
a = a + (int) Math.pow(2, j) * b;
System.out.print(a + " ");
}
System.out.println(""); //줄 바꿈
Result
1 2 | 2 6 14 30 62 126 254 510 1022 2046 8 14 26 50 98 | cs |
reference
Hackerrank (https://www.hackerrank.com/)
w3schools (www.w3schools.com)
'JAVA' 카테고리의 다른 글
instance in Java (0) | 2018.12.31 |
---|---|
main method in Java (0) | 2018.12.31 |
Java Data type (primitive & non-primitive) (0) | 2018.12.18 |
Scanner class in Java(User input) (0) | 2018.12.18 |
Displaying text in Java (println and printf) (0) | 2018.12.18 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- spring boot application
- 프로그래머스 알고리즘
- math.abs
- equals()
- rest parameter
- Javascript Algorithm
- HashMap
- hackerrank javascript
- algorithm
- hackerrank solution
- code refactoring
- HackerRank Algorithm
- substring()
- string class in java
- Object type casting
- hackerrank javascript solution
- javascript
- 알고리즘
- C++
- easy javascript algorithm
- Collection Framework
- repeat()
- compareTo()
- 프로그래머스
- math.max
- 프로그래머스 알고리즘문제
- hackerrank
- ... in Javascript
- easy algorithm
- java
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
30 | 31 |
글 보관함