본문 바로가기

Level 1 - 스트링을 숫자로 바꾸기 strToInt 메소드는 String형 str을 매개변수로 받습니다. str을 숫자로 변환한 결과를 반환하도록 strToInt를 완성하세요. 예를들어 str이 1234이면 1234를 반환하고, -1234이면 -1234를 반환하면 됩니다. str은 부호(+,-)와 숫자로만 구성되어 있고, 잘못된 값이 입력되는 경우는 없습니다. 풀이 public class StrToInt { public int getStrToInt(String str) { return Integer.parseInt(str); } //아래는 테스트로 출력해 보기 위한 코드입니다. public static void main(String args[]) { StrToInt strToInt = new StrToInt(); System.out.pri.. 더보기
Common Elements in Two Sorted Arrays (Java) Write a function that returns the common elements (as an array) between two sorted arrays of integers (ascending order).Example: The common elements between [1, 3, 4, 6, 7, 9] and [1, 2, 4, 5, 9, 10] are [1, 4, 9]. 풀이 import java.util.ArrayList;import java.util.HashMap;import java.util.List; public class CE { public static void main(String[] args) { // NOTE: The following input values are used f.. 더보기
Day 5: Loops 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 FormatA single integer, .ConstraintsOutput FormatPrint lines of output; each line (where ) contains the of in the form: n x i = result.Sample Input2 Sample Output2 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 .. 더보기