Q1.
1
22
333
4444
55555
int[] arr = {1,2,3,4,5};
for(int i=0;i<5;i++){
for(int j=0;j<i+1;j++){
System.out.print(arr[i]);
}
System.out.println();
}
다른방법
int limit = 6;
String[] arr2 = new String[limit];
for(int i=0;i<limit;i++){
arr2[i]="";
for(int j=0;j<=i;j++){
arr2[i]+=i+1+"";
}
}
for(int i=0;i<limit;i++){
System.out.println(arr2[i]);
}
Q2.
* * *
* *
* * *
* *
* * *
char[] arr = new char[25];
for(int i=0;i<25;i++){
if(i%2==0){
arr[i]='*';
}else{
arr[i]=' ';
}
if(i%5==0){
System.out.println();
}
System.out.print(arr[i]);
}
Q3.
*
*
*
*
*
char[] st = new char[10];
for(int i=0;i<5;i++){
for(int j=0;j<i+1;j++){
if(j==i){
st[i]='*';
System.out.print(st[i]);
}else{
st[i]=' ';
System.out.print(st[i]);
}
}
System.out.println();
}
Q4.
arr={24,33,17,44,2};
로또 번호는 2,17,24,33,44 입니다.
int[] arr = {24,33,17,44,2};
int tmp;
for(int i=0;i<arr.length-1;i++){ //오름차순
for(int j=i+1;j<arr.length;j++){
if(arr[i]>arr[j]){
tmp=arr[i];
arr[i]=arr[j];
arr[j]=tmp;
}
}
}
for (int i=0; i<arr.length;i++) {
if (i==arr.length-1) {
System.out.print(arr[i] + "입니다");
} else if (i == 0) {
System.out.print("로또 번호는 " + arr[i] + ",");
} else {
System.out.print(arr[i] + ",");
}
}
'* Programming > JAVA' 카테고리의 다른 글
DAY12 Lotto구매하기 결과발표(static메소드) (0) | 2016.07.21 |
---|---|
JAR로 export 하기 (0) | 2016.07.19 |
DAY12 배열 (0) | 2016.07.19 |
DAY11 class 정리/상수화 (0) | 2016.07.18 |
DAY10 업다운 게임 (0) | 2016.07.18 |