2013년 2월 21일 목요일

4일차 - for

 
/*
for문
    -형식:
         
      for(1;2;3){
      //1.반복변수(선언,초기화가능)
      //2.반복변수의 조건검사(논리형데이타)
      //3.반복변수증,감(++,--)
      }
   
      ex>
      for(int i=0;i<10;i++){
      stmt1;
      }
      ex>무한루프
      for(;;){
     
      }

*/
public class ForTest {

public static void main(String[] args) {
System.out.println("===========================");
for(int i=0 ; i<5 ; i++){
System.out.println("i="+i);
}
System.out.println("==========1==============");
/*
* 1. 1~10까지의 정수중에서 4로 나누어 떨어지는 수를 출력하시오.
* 2. 1~10까지의 정수중에서 홀수의 합을 구하세요.
* 3. 알파벳 소문자를 출력하세요.
*/
for(int i=0; i<10 ;i++){
int su = i+1;
if(su%4==0){
System.out.print(su);
}else{
System.out.print(" ");
}
}
System.out.println();
System.out.println("==========2===============");
int tot = 0 ;
for(int i = 0 ; i<10 ; i++ ){
int su = i+1;
if(su%2==1){
//tot = tot + su ;
tot+=su;
/*
* 연산후대입연산자
* tot+=su; ㅡㅡ> tot=tot+su
* tot-=su; ㅡㅡ> tot=tot-su
* tot*=su; ㅡㅡ> tot=tot*su
* tot/=su; ㅡㅡ> tot=tot/su
*/


}

}System.out.println(tot);
System.out.println();
System.out.println("==========3===============");
int count=0;
for(char c='a' ; c <= 'z' ; c++){

count++;
System.out.print(c+" ");
if(count%4==0){
System.out.println();
}
}
System.out.println();
System.out.println("==========4===============");

//감소

for(int i=4 ; i>=0 ;i--){
System.out.println("i="+i);

}
System.out.println();
System.out.println("==========5===============");

for(char c='z' ; c >= 'a' ; c--){


System.out.print(c);

}
System.out.println();
System.out.println();
System.out.println("==========6===============");
// 2씩 증가
for(int i=0 ; i <10 ; i=i+2){
System.out.print(i+" ");
}
System.out.println();
System.out.println("==========7===============");
// 2씩 감소
for(int i = 10 ; i >= 0 ; i=i-2){
System.out.print(i+" ");
}

}

}
-----------------------------------------------

public class WhileGuGuDan {

public static void main(String[] args) {

int i=0;
while (i+2<10){

int a= i+2;

int j=0;
while(j<9){

int b= j+1;
System.out.print(a+"*"+b+"="+a*b+"  ");
j++;
}
System.out.println();
i++;
}

}

}
-----------------------------------------------


public class ForGuGuDan {


public static void main(String[] args) {

for(int i=0 ; i+2<10;i++){

int a=i+2;


for (int j = 0; j < 9; j++) {

int b=j+1;
System.out.print(+a+"*"+b+"="+a*b+"  ");
}
System.out.println();
}

}

}

-------------------------------------------------------

public class NestedFor {


public static void main(String[] args) {

/*
* ★★★★★
* ★★★★★
* ★★★★★
* ★★★★★
* ★★★★★
*/
for(int i = 0;i<5;i++){

for(int j = 0 ; j<5; j++){
System.out.print("★["+i+","+j+"]");
}

System.out.println();
}
System.out.println();
System.out.println("=========================");
for(int i=0; i<5 ; i++){
for(int j=0;j<5;j++){
if(i==j){
System.out.print("☆");
}else{
System.out.print("★");
}
}System.out.println();
}
System.out.println();
System.out.println("=========================");
for(int i=0 ; i<5 ; i++){
System.out.print("★★");
System.out.println("☆☆");
}
}

}
















댓글 없음:

댓글 쓰기

국정원의 댓글 공작을 지탄합니다.

UPBIT is a South Korean company, and people died of suicide cause of coin investment.

 UPBIT is a South Korean company, and people died of suicide cause of coin. The company helps the people who control the market price manipu...