본문 바로가기
Java 개발자 수업 강의노트/Java 소스

1, 10, 2, 9, 3, 8, 4, 7, 5, 6 출력하기

by 캬캬백곰 2012. 4. 19.
728x90

#한 수는 순차적 증가, 한 수는 순차적 감소되는 값을 출력하기

결과: 1    10    2    9    3    8    4    7    5    6

 

public class For2 {

 /**
  * @param args
  */
 public static void main(String[] args) {
  // TODO Auto-generated method stub
  
  int a=0;
  int b=11;
  
  for(int i=1; i<=5; i++){
   a=a+1;
   b=b-1;
   System.out.print(a+"\t"+b+"\t");
  }
  
  System.out.println(); // 한 줄 내리기

  int c=0;
  int d=11;
  int x;
  int y;
  
  for(int i=1; i<=5; i++){
   x=c+i;
   y=d-i;
   System.out.print(x+"\t"+y+"\t");
  }
  
  System.out.println(); // 한 줄 내리기
  
  int num=10;
  
  for(int i=1; i<=5; i++){
   System.out.print(i+"\t"+num+"\t");
   num--; // num=num-1과 같음
  }
  
  System.out.println(); // 한 줄 내리기
  
  for(int i=1; i<=5; i++){
   System.out.print(i+"\t"+(11-i)+"\t");
  }

 }

}

*네 가지 소스 모두 같은 값을 출력한다.

728x90
반응형

'Java 개발자 수업 강의노트 > Java 소스' 카테고리의 다른 글

1-100의 합  (0) 2012.04.19
20, 19, 17, 14...출력하기  (0) 2012.04.19
1, 10, 18, 25...출력하기  (0) 2012.04.19
짝수 출력하는 프로그램(2)  (0) 2012.04.19
짝수 출력 방법  (0) 2012.04.18