86. 콘솔에서 세개의 정수( a, d, n )를 입력받고, a를 시작값, d를 등차값으로 가지는 등차수열의 n번째 값을 출력하라.
입력: 1Line 에 공백을 두고 3개의 정수가 입력됨
입력 범위 : 0 ~ 100
입력 예시
1 3 5
출력 예시
13
JAVA
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int startNum = scan.nextInt();
int addNum = scan.nextInt();
int targetIndex = scan.nextInt();
scan.close();
int result = startNum;
for (int i = 1; i < targetIndex; i++) {
result += addNum;
}
System.out.println(result);
}
}
Swift 4.2
import Foundation
if let line = readLine(){
let valueArray = line.split(separator: " ")
if valueArray.count == 3,
let startNum = Int(valueArray.first!),
let addNum = Int(valueArray[1]),
let targetIndex = Int(valueArray[2])
{
var result = startNum
for _ in 1 ..< targetIndex {
result += addNum
}
print(result)
}
}
뭘 사용해보라는 문제였을까요?....
모르겠다
반응형
'iOS > CodeUP - 기초100 With Swift' 카테고리의 다른 글
1091 : [기초-종합] 수 나열하기3 with Swift (0) | 2021.06.25 |
---|---|
1090 : [기초-종합] 수 나열하기2 with Swift (0) | 2021.06.23 |
1088 : [기초-종합] 3의 배수는 통과? with Swift (0) | 2021.06.23 |
1087 : [기초-종합] 여기까지! 이제그만~ with Swift (0) | 2021.06.22 |
1086 : [기초-정보] 그림 파일 저장용량 계산하기 with Swift (0) | 2021.06.22 |