문제
컵 3개 중 하나에 임의로 공(O)을 숨기고 공의 위치를 맞추는 문제입니다 이를 해결하는 프로그램의 다음 실행상태에 대해 빈칸을 채우세요
프로그램의 실행순서 및 실행상태
1 public static void main( String[] args ) {
2 int ball = (int)( Math.random() * 3 ) + 1;
3 System.out.println( " | 1 | | 2 | | 3 | \n\n\n" );
___ ___ ___
| | | | | |
| 1 | | 2 | | 3 |
4 int cup = scan.nextInt();
1, 2, 3 중에서 공을 숨긴 컵을 찾으세요: 1
5 System.out.print( " \033[4;" + (ball*7-3) + "fO\n \033[5;" + (cup*7-5) + "f" );
___ ___ ___
| | | | | |
| 1 | | 2 | | 3 |
O
6 System.out.print( ( cup == ball ) ?
___ ___ ___
| | | | | |
| 1 | | 2 | | 3 |
O
찾았다!
7 "찾았다!" :
9 }
프로그램 코드
import java.util.Scanner;
public class FindBall
{
1 public static void main( String[] args ) {
Scanner scan = new Scanner( System.in );
2 int ball = (int)( Math.random() * 3 ) + 1;
System.out.println( " ___ ___ ___ " );
System.out.println( " | | | | | | " );
3 System.out.println( " | 1 | | 2 | | 3 | \n\n\n" );
System.out.print( " 1, 2, 3 중에서 공을 숨긴 컵을 찾으세요: " );
4 int cup = scan.nextInt();
5 System.out.print( " \033[4;" + (ball*7-3) + "fO\n \033[5;" + (cup*7-5) + "f" );
6 System.out.print( ( cup == ball ) ?
7 "찾았다!" :
8 "놓쳤다!" );
scan.close();
9 }
}