본문 바로가기

알고리즘 문제연습33

[019] 거듭제곱 코드 문제 - n의 m승의 결과를 출력하세요 - n : 5 m : 3 정답: 125 보완할 점 소스코드 public class Algorithm19 { public static void main(String[] args) { // n의 m승의 결과물을 출력하세요 int n = 5; int m = 3; int xnum = n; //곱한 것을 누적할 변수 xnum for(int i = 1; i < m; i++) { xnum = xnum * n; } System.out.println("정답: " + xnum); } } 2021. 6. 2.
[018] 별 찍기 (하나씩 증가) 문제 - n에 따라 달라지는 아래와 같은 별 찍기를 완성하세요 n : 5 * ** *** **** ***** - 중첩반복문 이용 보완할 점 소스코드 public class Algorithm18 { public static void main(String[] args) { int n = 5; for(int i = 1; i = 1; j--) { // 5 4 3 2 1 if(i >= j) { System.out.print("*"); }else if(i < j) { System.out.print(" "); } } System.out.println(); } } } 2021. 6. 2.
[020] 369 삼육구 게임 코드 문제 - 3,6,9 게임을 코드로 구현하세요 보완할 점 소스코드 public class Algorithm20 { public static void main(String[] args) { //3 6 9 게임, 100까지 String[] str = new String[100]; int snum = 1; //1~100까지 배열에 담아두기 for(int i = 0; i < str.length; i++) { str[i] = snum + ""; snum++; } //하나씩 꺼내서 검사 for(int i = 0; i < str.length; i++) { boolean flag = true; //flag 초기화 for(int j = 0; j < str[i].length(); j++) { if( (str[i].charA.. 2021. 6. 1.
[017] 별 찍기 (하나씩 감소) 문제 - n에 따라 달라지는 아래와 같은 별 찍기를 완성하세요 n : 5 ***** **** *** ** * - 중첩반복문 이용 보완할 점 소스코드 public class Algotithm17 { public static void main(String[] args) { int n = 5; for(int i = 1; i 2021. 5. 29.
[016] 별 찍기 (하나씩 증가) 문제 - n에 따라 달라지는 아래와 같은 별 찍기를 완성하세요 n : 5 * ** *** **** ***** - 중첩반복문 이용 보완할 점 소스코드 public class Algotithm16 { public static void main(String[] args) { int n = 5; for(int i = 1; i 2021. 5. 29.
[015] 구구단 출력하기 문제 - s단 ~ f단까지 구구단을 출력하세요 - 중첩반복문 이용 보완할 점 소스코드 public class Algotithm15 { public static void main(String[] args) { int snum = 2; int fnum = 5; for(int j = 1; j < 10; j++) { for(int i = snum; i 2021. 5. 29.