/*문제
1) 문자 배열이 있다. 특정 문자를 다른 문자로 교체
2) 배열 데이터 예:
char[] chars = {'i', 'n', 't', 'e', 'g', 'e', 'r'};
char ch1 = 't';
char ch2 = 'x';
3) 실행 및 출력 예:
>java Test
결과: inxeger

 

 

 

class Test{

 public static void main(String[] args) throws Exception {

   char[] chars = {'i', 'n', 't', 'e', 'g', 'e', 'r'};
   char ch1 = 't';
   char ch2 = 'x';

   for (int i = 0; i < chars.length; i++) {
     if (chars[i] == ch1) {
       chars[i] = ch2;
     }
   }

   for (char i : chars) {
     System.out.printf("%c \n",  i);
   }
  }
}

Posted by 안낭우훗

/*문제: 19
  1) 분모, 분자 두 개의 배열이 있다. 나눈 계산 결과 중에서 가장 큰 수를 출력하라!
  2) 배열 데이터 예:
  int[] numerator = {5, 2, 5};
  int[] denominator = {6, 3, 4};
  3) 출력 예:
  결과: 5/4

 

 

 

public class Test {
  public static void main(String[] args) {
    int[] numerator = {5, 2, 5, 2};
    int[] denominator = {6, 3, 4, 7};

 

    int maxIndex = 0;
    for (int i = 1; i < numerator.length; i++) {
      if (numerator[maxIndex] * denominator[i] <
          numerator[i] * denominator[maxIndex] ) {
        maxIndex = i;
      }
    }
    System.out.printf("결과: %d/%d\n", numerator[maxIndex], denominator[maxIndex]);

  }

}

Posted by 안낭우훗

 

/*문제: 18
  1) 배열이 등비수열인지 여부를 확인한다.
  2) 배열 데이터 예:
  int[] list = {1, 4, 16, 64, 256};
  3) 출력 예:
  {1, 4, 16, 64, 254} : 등비수열이다.
  {1, 4, 16, 32, 128} : 등비수열이 아니다.
  4) 등비수열 이란.
  제 n항과 제 n+1항의 비가 일정한 수열.

 

 

class Test{

 public static void main(String[] args) throws Exception {

 int[] list = {1, 4, 16, 64, 256};

 boolean result = true;

 for (int i = 2; i < list.length; i++) {
   if ( list[0] * list[i] != list[i-1] * list[1]) {
     result = false;
     break;
   }
 }
 System.out.print("{");
 for (int i = 0; i < list.length; i++) {
   if (i > 0)
     System.out.print(", ");
   System.out.print(list[i]);
 }
 System.out.printf("} : %s\n",
   (result ? "등비수열입니다." : "등비수열이 아닙니다."));

  }
}

Posted by 안낭우훗
이전버튼 1 2 3 4 5 6 7 ··· 17 이전버튼

블로그 이미지
좋은싸이트 공유, 재해석 , 공부 정리, 틀린거 알려 주세요~
안낭우훗

태그목록

공지사항

Yesterday
Today
Total

달력

 « |  » 2025.7
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

최근에 올라온 글

최근에 달린 댓글

글 보관함