diff --git a/src/practice02/Prob01.java b/src/practice02/Prob01.java index 8dbc760..4e99c4e 100644 --- a/src/practice02/Prob01.java +++ b/src/practice02/Prob01.java @@ -1,9 +1,66 @@ package practice02; +import java.util.Scanner; + +/* + * +키보드에서 정수로 된 돈의 액수를 입력 받아 오만 원권, 만원 권, 오천 원권, 천원 권, +500원 동전, 100원 동전, 50원 동전, 10원 동전, 1원 동전 각 몇 개로 변환 되는지 작성하시오. + +<결과 값> +금액: 67879 + +50000원 : 1개 +10000원 : 1개 +5000원: 1개 +1000원: 2개 +500원: 1개 +100원: 3개 +50원:1개 +10원:2개 +5월:1개 +1원:4개 + + * */ + public class Prob01 { public static void main(String[] args) { final int[] MONEYS = { 50000, 10000, 5000, 1000, 500, 100, 50, 10, 5, 1 }; + int[] num=new int[MONEYS.length]; + Scanner scanner=new Scanner(System.in); + System.out.print("금액 : "); + int target=scanner.nextInt(); + scanner.close(); + + /*for(int i=0;i=standard) { + num[i]+=1; + target-=standard; + } + }*/ + + /*for(int i=0;i +5개의 숫자를 입력하세요. +10 +20 +30 +40 +50 +평균은 30.0 입니다. + * */ +public class Prob02 { public static void main(String[] args) { - } + Scanner in = new Scanner(System.in); + int intArray[] = new int[5]; + double sum = 0; + /* 키보드에서 배열 크기만큼 입력 받아 배열에 저장하는 코드 */ + System.out.println("5개의 숫자를 입력하세요."); + for(int i=0; i< intArray.length;i++) { + intArray[i]=in.nextInt(); + } + /* 배열에 저장된 정수 값 더하기 */ + for(int i=0;i +This is a pencil +This,is,a,pencil + + * */ public class Prob03 { public static void main(String args[]) { @@ -14,5 +26,25 @@ public static void main(String args[]) { // 수정된 배열 원소 출력 printCharArray(c); } + + public static void replaceSpace(char[] a) { + // TODO Auto-generated method stub + for(int i=0;i +dlroW olleH +!gnimmargorP avaJ + + * */ public class Prob04 { public static void main(String[] args) { @@ -11,10 +21,25 @@ public static void main(String[] args) { } public static char[] reverse(String str) { - /* 코드를 완성합니다 */ + /* 코드를 완성합니다 + * + * - 문자열의 순서를 뒤집어서 char 배열로 리턴하는 메소드를 구현한다 + - 예를 들어 “Hi!” 라는 문자열을 파라미터로 전달 하면 {‘!’, ‘i’, ‘H’ } 배열을 반환 한다. + + * */ + String revereStr=new StringBuffer(str).reverse().toString(); + return revereStr.toCharArray(); + } public static void printCharArray(char[] array){ - /* 코드를 완성합니다 */ + /* 코드를 완성합니다 + * + * - char[]을 받아들여 출력한다. + - {‘!’, ‘i’, ‘H’} 배열을 파라미터로 전달하면 다음과 같이 출력된다. + !iH + + * */ + System.out.println(array); } } diff --git a/src/practice02/Prob05.java b/src/practice02/Prob05.java index 0e54b0f..a2dd197 100644 --- a/src/practice02/Prob05.java +++ b/src/practice02/Prob05.java @@ -1,10 +1,89 @@ package practice02; +import java.util.Random; +import java.util.Scanner; + +/* + * +숨겨진 카드의 수를 맞추는 게임입니다. 1-100까지의 임의의 수를 가진 카드를 한 장 +숨기고 이 카드의 수를 맞추는 게임입니다. 아래의 화면과 같이 카드 속의 수가 57인 경 +우를 보면 수를 맞추는 사람이 40이라고 입력하면 "더 높게", 다시 75이라고 입력하면 +"더 낮게" 라는 식으로 범위를 좁혀가며 수를 맞추고 있습니다. 게임을 반복하기 위해 +y/n이라고 묻고 n인 경우 종료됩니다.. + +---------------------------------------------------------- + +처음 숨길 카드를 선택하기 위해서는 다음과 같이 Random 클래스를 이용하여 +1~100까지의 임의의 정수를 생성합니다. + +import java.util.Random; + +Random r = new Random(); +int k = r.nextInt(100) + 1; + +---------------------------------------------------------- + +"다시 하시겠습니까(y/n)>>"에 대한 대답으로 사용자가 "y"나 "n"을 입력받고 +비교하기 위해 다음의 코드를 사용합니다. + +String answer = scanner.next(); +if( answer.equlas("n") ){ + //종료하도록 작성한다. +} + + + * */ public class Prob05 { public static void main(String[] args) { + Random r=new Random(); + Scanner scanner=new Scanner(System.in); + int k=0; + int count=0, target=1, frontRange=1, endRange=100; + boolean start=true; + + while(true) { + + if(start) { + k=r.nextInt(100) + 1; //nextInt(int index) : 0~index 범위에서 임의의 숫자 추출 + System.out.println("수를 결정하였습니다. 맞추어 보세요"); + frontRange=1; + endRange=100; + count=0; + start=false; + } + System.out.println(frontRange+"-"+endRange); + System.out.print(++count +">>"); + target = scanner.nextInt(); + + if(target>endRange || targettarget) { + System.out.println("더 높게"); + frontRange=target; + }else { + System.out.println("맞았습니다."); + + + System.out.print("다시 하시겠습니까(y/n)>>"); + String answer = scanner.next(); + + if(answer.equals("n")) { + + }else if(answer.equals("y")) { + start=true; + } + } + } } }