자신이 for문 잘쓴다는 사람만 푸시오

40 views
Skip to first unread message

cybe...@gmail.com

unread,
Feb 13, 2013, 9:59:30 PM2/13/13
to kor...@googlegroups.com

구구단을 짜는데

1단은 세로로 9까지

그옆에 2단~8, 세로로 

그옆에 3단~7, 세로로

그옆에 4단~6, 세로로

그옆에 5단~5, 세로로

그옆에 6단~6, 세로로

그옆에 7단~7, 세로로

그옆에 8단~8, 세로로

그옆에 9단~9, 세로로

그림참조 (비대칭 알고리즘)


권기륜

unread,
Feb 14, 2013, 12:55:47 AM2/14/13
to kor...@googlegroups.com
public class Gugudan {
public static void main(String[] args) {
  int i,j;
  int a,b;
  
  for(i=1;i<6;i++){
  for(j=1;j<10;j++){
  System.out.printf("%d*%d=%2d ",j,i,i*j);
  }
  System.out.printf("\n");
  }
  
  for(a=6;a<10;a++){
  for(b=1;b<=4;b++){
  if(b<=10-a)
  System.out.printf("%d*%d=%2d ",b,a,a*b);
  else
  System.out.printf("       "); 
  
  }
  for(b=5;b<10;b++){
  if(b>=a)
  System.out.printf("%d*%d=%2d ",b,a,a*b);
  else
  System.out.printf("       ");
  
  }
  System.out.printf("\n");
  }
}
}

cybe...@gmail.com

unread,
Feb 14, 2013, 2:28:55 AM2/14/13
to kor...@googlegroups.com
int o = 9;
for (int i = 1; i < 10; i++) {
for (int j = 1; j < 10; j++) {
if(j<6)o--;
else o++;
if(o >= 0 )
      System.out.print(j  + " X " + i + " = " + (i* j) + "\t");
//System.out.print(i*j + "\t");
else System.out.print("\t\t");
}
System.out.println();
}
System.out.println();
Reply all
Reply to author
Forward
0 new messages