import java.util.Scanner;
public class test1 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
int tmp = num;
int odd = 1;
for(int i = 0; i < num; i++) {
for(int j = 0; j < (tmp-1); j++) {
System.out.print(" ");
}
for(int j = 0; j < odd; j++) {
System.out.print("*");
}
odd += 2;
tmp--;
System.out.println();
}
}
}
🟢 층수를 입력받고 층수 - 1
값에서 하나씩 줄이면서 공백 출력
🟢 1개의 별부터 2개씩 늘려가며 *
출력
import java.util.Scanner;
public class test2 {
public static void main(String[] args) {
int randomVal = (int)(Math.random()*100) + 1;
int tryVal = 1;
int cnt = 10;
Scanner sc = new Scanner(System.in);
int num;
while(tryVal <= cnt) {
System.out.print("정답을 추측하여 보시오: ");
num = sc.nextInt();
if(num > randomVal) {
System.out.println("LOW");
}
else if(num < randomVal) {
System.out.println("HIGH");
}
else {
break;
}
tryVal++;
}
if(tryVal <= cnt) {
System.out.println("축하합니다. 시도횟수=" + tryVal);
}
else {
System.out.println("실패했습니다.");
}
}
}
🟢 10번 이내에 맞춘다면, 축하합니다
메세지와 함께 시도횟수 출력
🟢 10번 동안 맞추지 못했다면, 실패했습니다
출력