파일명:ForSample.java

public class ForSample{
  public static void main(String[] args){
/*
등수구하는 알고리즘
★★★★★
★★★★★
★★★★★
★★★★★
★★★★★
*/

      int p,q;

   for(p=1;p<=5;p++)
   {
    for(q=1;q<=5;q++)
    {
     System.out.print("★");
    }

    System.out.println();
   }

/*
@★★★★
★@★★★
★★@★★
★★★@★
★★★★@
*/
   for(p=1;p<=5;p++)
   {
    for(q=1;q<=5;q++)
    {
     if(p==q)
      System.out.print("@");
     else
      System.out.print("★");
    }

    System.out.println();
   }

/*
정렬 알고리즘

★★
★★★
★★★★
★★★★★
*/
   for(p=1; p<=5; p++)
   {
    for(q=1; q<=p; q++)
    {
              System.out.print("★");
    }

    System.out.println();
   }
/*
★★★★★
★★★★
★★★
★★

*/
   for(p=5; p>=1; p--)
   {
    for(q=1; q<=p; q++)
    {
     System.out.print("★");
    }

    System.out.println();
   }

  }
}

'..열심히 공부하세.. > JAVA 문법' 카테고리의 다른 글

[10] 반복문 while, do~while문  (0) 2012.04.19
[09] break와 continue  (0) 2012.04.19
[08] 이중 for문 예제  (0) 2012.04.19
[07] 반복문 (for)  (0) 2012.04.19
[06] 조건문 (if문, switch~case문)  (0) 2012.04.17

+ Recent posts