/*문제: 16 [swap]
  1) 두 수의 값을 서로 바꿔라.
  2) 데이터 예:
  int leftValue = 10, rightValue = 5;
  3) 출력 예:
  leftValue: 5, rightValue: 10
  list[0]: 5, list[1]: 10
  */

 

 

 

class Test{

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

   int leftValue = 10;
   int rightValue = 5;
   int temp;

   temp = leftValue;
   leftValue = rightValue;
   rightValue = temp;

   System.out.printf("leftValue: %d, rightValue: %d\n", leftValue, rightValue);

   int[] lists = {10, 5, 0};
   lists[2] = lists[0];
   lists[0] = lists[1];
   lists[1] = lists[2];
   System.out.printf("list[0]: %d, list[1]: %d", lists[0], lists[1]);
  }
}

Posted by 안낭우훗

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

태그목록

공지사항

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

최근에 올라온 글

최근에 달린 댓글

글 보관함