/*
* 12345
* 1234
* 123
* 12
* 1
* 12
* 123
* 1234
* 12345
*/
public class Exam_20 {
public static void main(String[] args) {
int co = 6;
for(int i=1; i<=9; ++i) {
if (i <= 5) {
--co;
}else {
++co;
}
for(int j=1; j<=co; ++j) {
System.out.print(j);
}
System.out.println();
}
}
}
/*
☆
1
12
123
1234
12345
1234
123
12
1
*/
public class Exam_19 {
public static void main(String[] args) {
int co = 0;
for(int i=1; i<=9; ++i) {
if(i<=5) { // i = 1, 2, 3, 4, 5
++co;
}else { // i = 6, 7, 8, 9
--co;
}
for(int j=1; j<=co; ++j) {
System.out.print(j);
}
System.out.println();
}
}
}
제어문
1. 조건(분기)제어문 (1회 실행)
if
1형식 : if (조건) {참}
2형식 : if (조건) {참} else {거짓}
3형식 : if (조건) {참} else if (조건) {참} else {거짓}
switch ~ case
Math.random()값에 원하는 값을 곱한다 (ex *10)
나온값을 int로 형변환해준다. (0~9)
+1을 해준다. (1~10)