공책

자바로 심리 숫자 구현하기 본문

웹 개발/Java

자바로 심리 숫자 구현하기

QTHoney 2013. 8. 28. 09:46

04, 05, 06, 07, 12

13, 14, 15, 20, 21

22, 23, 28, 29, 30


16, 17, 18, 19, 20

21, 22, 23, 24, 25

26, 27, 28, 29, 30


01, 03, 05, 07, 09

11, 13, 15, 17, 19

21, 23, 25, 27, 29


08, 09, 10, 11, 12

13, 14, 15, 24, 25

26, 27, 28, 29, 30


02, 03, 06, 07, 30

10, 11, 14, 15, 18

19, 22, 23, 26, 27


1~ 30까지 중의 숫자를 임의로 생각해서


각 번호 그룹에 숫자가 있으면 그룹 맨 앞의 숫자를 더하고


없으면 더하지않고 다음 그룹으로 넘어가는 코드를 구현해

package magic;


import java.util.Scanner;



public class Magic {

public static void main(String[] args) {

int arr1[] = { 4, 5, 6, 7, 12, 13, 14, 15, 20, 21, 22, 23, 28, 29, 30 };

int arr2[] = { 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30 };

int arr3[] = { 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29 };

int arr4[] = { 8, 9, 10, 11, 12, 13, 14, 15, 24, 25, 26, 27, 28, 29, 30 };

int arr5[] = { 2, 3, 6, 7, 30, 10, 11, 14, 15, 18, 19, 22, 23, 26, 27 };

int result = 0;

String str1 = "";

Scanner sc = new Scanner(System.in);

System.out.println("숫자 하나를 생각하세요");

System.out.println("다음 중 당신이 생각한 숫자가 있나요? y / n");

System.out.println("04, 05, 06, 07, 12, 13, 14, 15, 20, 21, 22, 23, 28, 29, 30");

str1 = sc.next();

if(str1.equals("y")){

result += arr1[0];

}

System.out.println("다음 중 당신이 생각한 숫자가 있나요? y / n");

System.out.println("16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30");

str1 = sc.next();

if(str1.equals("y")){

result += arr2[0];

}

System.out.println("다음 중 당신이 생각한 숫자가 있나요? y / n");

System.out.println("1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29");

str1 = sc.next();

if(str1.equals("y")){

result += arr3[0];

}

System.out.println("다음 중 당신이 생각한 숫자가 있나요? y / n");

System.out.println("8, 9, 10, 11, 12, 13, 14, 15, 24, 25, 26, 27, 28, 29, 30");

str1 = sc.next();

if(str1.equals("y")){

result += arr4[0];

}

System.out.println("다음 중 당신이 생각한 숫자가 있나요? y / n");

System.out.println("2, 3, 6, 7, 30, 10, 11, 14, 15, 18, 19, 22, 23, 26, 27");

str1 = sc.next();

if(str1.equals("y")){

result += arr5[0];

}

System.out.println("당신이 생각한 숫자는 " + result + "입니다.");


}

}



'웹 개발 > Java' 카테고리의 다른 글

잔액이 남지않게 물건을 구입하는 경우의 수  (0) 2013.08.28
최소 공배수 구하기  (0) 2013.08.28
for 문  (0) 2013.08.26
계산기 만들기  (0) 2013.08.26
키입력을 받는 switch ~ case 문  (0) 2013.08.26
Comments