Java를 이용한 가위바위보 게임
2021. 7. 17. 22:13
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
package RockScissorPaper;
import java.util.Random;
import java.util.Scanner;
public class Rsp {
public static void main(String[] args) {
Random rand = new Random();
Boolean asker = true;
System.out.println("Welcome to Rock-Scissor-Paper Game!");
while(asker){
System.out.println("Choose // 1 : Rock , 2 : Scissor, 3 : paper");
System.out.println("If you want to end the game,");
System.out.println("just type other numbers except 1, 2 or 3");
int rand_choose = (int)(Math.random() * 3 + 1);
Scanner scan = new Scanner(System.in);
int choose = scan.nextInt();
if(1 != choose && 2 != choose && 3 != choose) {
asker = false;
} else if(choose == rand_choose) {
System.out.println("Draw!");
} else if(1 == choose && 2 == rand_choose || 2 == choose && 3 == rand_choose) {
System.out.println("Oh...You Lose :<");
} else {
System.out.println("Congratulations! You Win! :)");
}
}
System.out.println("Game Over");
}
}
|
cs |
'Computer Language > Java' 카테고리의 다른 글
(Java)Difference Between '==' and 'equals()' (0) | 2021.08.02 |
---|---|
이클립스(Eclipse) Java 단축키 (0) | 2021.07.21 |
Java를 이용한 동전 앞뒤 맞추기 (0) | 2021.07.17 |
Java를 이용한 Array(배열)만으로 만든 성적 관리 프로그램 (0) | 2021.07.15 |
Java 기본 자료형(Primitive Data Type) (0) | 2021.07.15 |