package AlgorithmEasy;
import java.util.Scanner;
public class Algorithm30 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("숫자를 입력하세요 >> ");
int num = sc.nextInt();
for(int i = 1; i <= num; i++) {
if(i % 2 == 1) { //홀수라면~
if(i != num) { //마지막 숫자 제외
System.out.print(i+"+");
}
}else {//짝수라면
if(i != num) { //마지막 숫자 제외
System.out.print(i+"-");
}
}
}
System.out.print(num);
}
}
'알고리즘 문제연습 > 기초 알고리즘' 카테고리의 다른 글
[프로그래머스] 크레인 인형 뽑기 게임 (0) | 2023.02.13 |
---|---|
[프로그래머스] 실패율 (0) | 2023.02.13 |
[029] 음계 (백준 2920번) (0) | 2021.06.17 |
[026] 상수 (백준 2908번) (0) | 2021.06.15 |
[025] 더하기 사이클 (백준 1110번) (0) | 2021.06.09 |
댓글