자바_기초
제어문 + 반복문 문제) if + for + array
잠수콩
2019. 5. 14. 08:43
package ControlFlow;
public class exam_if_for {
public static void main(String[] args) {
// TODO Auto-generated method stub
String t1 = "*";
for(int i=1; i <= 5; i++) {
// System.out.println("i=" + i);
for(int count=1; count <= 5; count++) {
// System.out.println("count=" + count);
if (i >= count) {
System.out.print(t1);
}
}
System.out.println();
}
System.out.println("=================");
String t2 = "1";
int arr[] = {1, 3, 5, 8, 6, 3, 1};
for(int i : arr) {
for (int j=1; j <= (8 - (i / 4)); j++) {
System.out.print(" ");
}
for (int j=1; j <= i; j++) {
System.out.print(t2);
}
System.out.println();
}
System.out.println("=================");
String t3 = "*";
for(int i=1; i <= 5; i++) {
// System.out.println("i=" + i);
for(int count=1; count <= 5; count++) {
if (i >= count) {
System.out.print(t3);
}
}
for (int j = 1; j <= 10 - ( i * 2); j++) {
System.out.print(" ");
}
for(int count=1; count <= 5; count++) {
if (i >= count) {
System.out.print(t3);
}
}
System.out.println();
}
}
}