forked from woowacourse-precourse/java-baseball-6
-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[숫자 야구 게임] 박해원 과제 제출합니다. #14
Open
haewonee
wants to merge
3
commits into
LandvibeDev:main
Choose a base branch
from
haewonee:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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 |
---|---|---|
@@ -1,7 +1,88 @@ | ||
package baseball; | ||
|
||
import java.util.Scanner; | ||
import camp.nextstep.edu.missionutils.Console; | ||
import camp.nextstep.edu.missionutils.Randoms; | ||
public class Application { | ||
public static void main(String[] args) { | ||
// TODO: 프로그램 구현 | ||
Scanner scanner= new Scanner(System.in); | ||
boolean option = true; | ||
while(option) { | ||
boolean sad = true; | ||
char[] ranArr = new char[3]; | ||
do { | ||
int random = Randoms.pickNumberInRange(123, 987); | ||
String randomStr = Integer.toString(random); //문자열로 바꾸기 | ||
//char 배열에 저장하기 | ||
for (int i = 0; i < 3; i++) { | ||
ranArr[i] = randomStr.charAt(i); | ||
} | ||
for (int i = 0; i < 3; i++) { | ||
System.out.print(ranArr[i]); | ||
} | ||
if (ranArr[0] != ranArr[1] && ranArr[1] != ranArr[2] && ranArr[0] != ranArr[2]) { | ||
if(ranArr[1]!=0&&ranArr[2]!=0){ | ||
sad=false; | ||
} | ||
} else { | ||
ranArr= new char[3]; | ||
continue; | ||
} | ||
}while(sad); | ||
|
||
//주석깃허브 | ||
while (true) { | ||
System.out.print("숫자를 입력해주세요: "); | ||
String sscore = scanner.nextLine(); | ||
try { | ||
if (sscore.length() != 3) { | ||
throw new IllegalArgumentException(); | ||
} | ||
|
||
char[] score = new char[3]; | ||
for (int i = 0; i < 3; i++) { | ||
score[i] = sscore.charAt(i); //숫자 하나하나 따로 나누기. 비교를 위해! | ||
} | ||
int ball = 0, strike = 0; | ||
|
||
for (int i = 0; i < 3; i++) { | ||
for (int j = 0; j < 3; j++) { | ||
if (i == j && score[i] == ranArr[j]) { | ||
strike++; | ||
} else if (i != j && score[i] == ranArr[j]) { | ||
ball++; | ||
} | ||
|
||
} | ||
} | ||
if (strike == 3) { | ||
System.out.println("3스트라이크\n3개의 숫자를 모두 맞히셨습니다! 게임종료"); | ||
System.out.println("게임을 새로 시작하려면 1, 종료하려면 2를 입력하세요."); | ||
int input = scanner.nextInt(); | ||
scanner.nextLine(); | ||
|
||
if (input == 2) { | ||
System.out.println("게임종료!"); | ||
option = false; | ||
break; | ||
} else if (input == 1) { | ||
break; | ||
} | ||
|
||
} else if (strike > 0 && ball > 0) { | ||
System.out.println(ball + "볼 " + strike + "스트라이크"); | ||
} else if (strike > 0) { | ||
System.out.println(strike + "스트라이크"); | ||
} else if (ball > 0) { | ||
System.out.println(ball + "볼"); | ||
} else if (ball == 0 && strike == 0) { | ||
System.out.println("낫싱"); | ||
} | ||
}catch(IllegalArgumentException e){ | ||
System.out.println("잘못된 입력입니다: "); | ||
return; | ||
} | ||
} | ||
|
||
} | ||
} | ||
} | ||
} |
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,5 @@ | ||
package baseball; | ||
|
||
public class Haewon { | ||
int a; | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ㅎㅇ