-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #57 from bellra-jin/main
feat: 문제 작성 완료
- Loading branch information
Showing
4 changed files
with
179 additions
and
0 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
src/main/java/com/ohgiraffers/parkjinhee/Application3.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package com.ohgiraffers.parkjinhee; | ||
|
||
import java.util.Scanner; | ||
|
||
public class Application3 { | ||
|
||
public static void main(String[] args) { | ||
System.out.println(rockPaperScissors()); | ||
System.out.println(printNumber()); | ||
} | ||
|
||
/* | ||
* static 메소드로 생성 | ||
* 반환형 : String | ||
* 메소드명 : rockPaperScissors | ||
* | ||
* 가위 바위 보 중 하나를 출력 | ||
* (가위, 바위, 보 는 난수를 이용하여 구현) | ||
* | ||
* -- 출력 -- | ||
* 가위 | ||
* */ | ||
public static String rockPaperScissors() { | ||
String[] choices = {"가위", "바위", "보"}; | ||
int randomIndex = (int) (Math.random() * 3); | ||
return choices[randomIndex]; | ||
} | ||
|
||
|
||
/* | ||
반환형 : String | ||
메소드명 : printNumber | ||
사용자로부터 한 개의 값을 입력 받아 1부터 그 숫자까지의 숫자들을 모두 출력하세요. | ||
단, 입력한 수는 1보다 크거나 같아야 합니다. | ||
만일 1 미만의 숫자가 입력됐다면 “1 이상의 숫자를 입력해주세요“를 출력하세요. | ||
ex. | ||
1이상의 숫자를 입력하세요 : 4 1 이상의 숫자를 입력하세요 : 0 | ||
1 2 3 4 1 이상의 숫자를 입력해주세요. | ||
* */ | ||
public static String printNumber() { | ||
Scanner sc = new Scanner(System.in); | ||
System.out.print("1이상의 숫자를 입력하세요: "); | ||
int N = sc.nextInt(); | ||
|
||
if (N < 1) { | ||
return "1 이상의 숫자를 입력해주세요."; | ||
} else { | ||
StringBuilder result = new StringBuilder(); | ||
for (int i = 1; i <= N; i++) { | ||
result.append(i).append(" "); | ||
} | ||
return result.toString().trim(); | ||
} | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
src/main/java/com/ohgiraffers/parkjinhee/Application4.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.ohgiraffers.parkjinhee; | ||
|
||
import java.util.Scanner; | ||
|
||
public class Application4 { | ||
|
||
public static void main(String[] args) { | ||
|
||
/* 길이가 5인 String 배열을 선언하고 | ||
* "딸기", "바나나", "복숭아", "키위", "사과" 로 초기화를 하고 | ||
* 스캐너로 0부터 4까지의 정수를 입력 받아 | ||
* 해당 정수의 인덱스에 있는 과일을 출력하세요 | ||
* | ||
* 단, 배열의 인덱스 범위를 벗어나는 경우 "준비된 과일이 없습니다." 를 출력하세요 | ||
* | ||
* -- 입력 예시 -- | ||
* 0부터 4까지의 정수를 입력하세요 : 2 | ||
* | ||
* -- 출력 예시 -- | ||
* 복숭아 | ||
* | ||
* -- 입력 예시 -- | ||
* 0부터 4까지의 정수를 입력하세요 : 5 | ||
* | ||
* -- 출력 예시 -- | ||
* 준비된 과일이 없습니다. | ||
* */ | ||
String[] fruits = {"딸기", "바나나", "복숭아", "키위", "사과"}; | ||
|
||
Scanner sc = new Scanner(System.in); | ||
|
||
System.out.print("0부터 4까지의 정수를 입력하세요 : "); | ||
|
||
int N = sc.nextInt(); | ||
|
||
if (N >= 0 && N < fruits.length) { | ||
System.out.println(fruits[N]); | ||
} else { | ||
System.out.println("준비된 과일이 없습니다."); | ||
|
||
} | ||
sc.close(); | ||
|
||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
src/main/java/com/ohgiraffers/parkjinhee/Application5.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.ohgiraffers.parkjinhee; | ||
|
||
import java.util.Scanner; | ||
|
||
public class Application5 { | ||
|
||
public static void main(String[] args) { | ||
|
||
/* 문자열을 하나 입력받아 문자 자료형 배열로 바꾼 뒤 | ||
* 검색할 문자를 하나 입력 받아 | ||
* 입력 받은 검색할 문자가 문자열에 몇개 있는지를 출력하세요 | ||
* | ||
* -- 입력 예시 -- | ||
* 문자열을 하나 입력하세요 : helloworld | ||
* | ||
* -- 출력 예시 -- | ||
* 입력하신 문자열 helloworld에서 찾으시는 문자 l은 3개 입니다. | ||
* */ | ||
|
||
Scanner sc = new Scanner(System.in); | ||
|
||
System.out.print("문자열을 하나 입력하세요 : "); | ||
String inputString = sc.nextLine(); | ||
|
||
char[] charArray = inputString.toCharArray(); | ||
|
||
System.out.print("검색할 문자를 하나 입력하세요: "); | ||
char searchChar = sc.nextLine().charAt(0); | ||
|
||
int count = 0; | ||
for (char c : charArray) { | ||
if (c == searchChar) { | ||
count++; | ||
} | ||
} | ||
|
||
System.out.printf("입력하신 문자열 %s에서 찾으시는 문자 %c은 %d개 입니다.\n", inputString, searchChar, count); | ||
|
||
sc.close(); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/main/java/com/ohgiraffers/parkjinhee/Application6.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.ohgiraffers.parkjinhee; | ||
|
||
import java.util.Scanner; | ||
|
||
public class Application6 { | ||
|
||
public static void main(String[] args) { | ||
|
||
/* 주민등록번호를 스캐너로 입력 받고 문자 배열로 저장한 뒤, | ||
* 성별 자리 이후부터 *로 가려서 출력하세요 | ||
* | ||
* -- 입력 예시 -- | ||
* 주민등록번호를 입력하세요 : 990101-1234567 | ||
* | ||
* -- 출력 예시 -- | ||
* 990101-1****** | ||
*/ | ||
|
||
Scanner sc = new Scanner(System.in); | ||
|
||
System.out.print("주민등록번호를 입력하세요 : "); | ||
|
||
String sn = sc.nextLine(); | ||
|
||
char[] snChars = sn.toCharArray(); | ||
|
||
for (int i = 8; i < snChars.length; i++) { | ||
snChars[i] = '*'; | ||
} | ||
|
||
System.out.println(snChars); | ||
|
||
sc.close(); | ||
|
||
} | ||
} |