UP & Down Game
자바 프로그래밍/코드 2020. 2. 11. 18:07

import java.util.Scanner; //UP & Down Game //1~99까지 범위의 랜덤한 숫자를 맞추는 게임 //게임점수 -> 현재까지의 최고기록은 n회입니다.(가장 빨리 맞췄을때) //플레이한적이 없을때 게임점수는-> 현재까지의 최고기록은 100회입니다 혹은 플레이한적 없습니다 출력 //컴퓨터enemy가 참여하여 함께 게임경쟁 //player와 enemy가 각자의 정보를 이용하여 경쟁 public class Quiz_01 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int com; //컴퓨터의 패 int player; //플레이어의 패 int enemy; //경쟁자 Enemy의 패 //i..

가위바위보 게임-Math.random()을 이용
자바 프로그래밍/코드 2020. 2. 11. 00:37

import java.util.Scanner; //가위바위보 게임 //가위바위보 중 하나를 선택, 승패를 결정하는 게임 public class Quiz_05 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int player=0; //플레이어 패 int com=0; //컴퓨터 패 int sw=0; //프로그램 재시작/종료 스위치 //가위바위보 프로그램 시작 while(true) { com = (int)(Math.random()*(3-1+1)+1); //컴퓨터 패 선택 //플레이어 패 입력 시작 while(true) { try {//플레이어 패 입력 System.out.println("=====가위 바위 보 게임..

동전 앞뒤 맞추기 게임-Math.random()을 이용
자바 프로그래밍/코드 2020. 2. 11. 00:36

import java.util.Scanner; //동전 앞뒤 맞추기 //1 또는 2의 랜덤수를 추출한뒤 사용자가 입력한 값과 비교 //사용자에게 숫자값을 입력 받아서, 난수와 일치하면 맞췄습니다 틀렸습니다. public class Quiz_04 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int input=0; int coin=0; int sw=0; while(true) { System.out.println("==== 동전 앞 뒤 맞추기 ===="); System.out.print("숫자를 입력해주세요 (1.앞면/2.뒷면) : "); input=Integer.parseInt(sc.nextLine()); co..

사용자가 원하는 랜덤범위의 값 추출 / 주사위 굴리기, 합계 구하기
자바 프로그래밍/코드 2020. 2. 11. 00:36

import java.util.Scanner; //사용자가 원하는 랜덤범위의 값 추출 public class Quiz_03 { public static void main(String[] args) { /* System.out.println("0~9까지의 랜덤수 : " + (int)(Math.random()*(9-0+1)+0)); System.out.println("1~10까지의 랜덤수 : " + (int)(Math.random()*(10-1+1)+1)); System.out.println("20~35까지의 랜덤수 : " + (int)(Math.random()*(35-20+1)+20)); System.out.println("0 또는 1 : " + (int)(Math.random()*(1-0+1)+0)); ..

ATM 시뮬레이터
자바 프로그래밍/코드 2020. 2. 11. 00:34

import java.util.Scanner; //ATM 시뮬레이터 public class Quiz_02 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int account=0; //잔액 int money=0; //입력으로 받을 입출금희망금액 변수 int menu=0; // 입력으로 받을 메뉴번호 변수 while(true) { //ATM 시뮬레이터 시작 //메뉴번호 입력 및 숫자가 아닌 값에 대한 예외처리 while(true) { try { System.out.println("*** ATM 시뮬레이터***"); System.out.println("1.잔액조회"); System.out.println("2.입금하..

난수(Random Number)
자바 프로그래밍/코드 2020. 2. 11. 00:33

//난수(Random Number) public class Exam_03 { public static void main(String[] args) { double d =Math.random(); // double형, 난수생성method //Math.random() : double값중 난수를 생성해주는데 0~1 사이의 숫자다. System.out.println((int)(d * 10)); // 0~9사이의 난수 출력. 10을 곱하고 int로 casting하는 방법. System.out.println((int)(d * 3 + 1)); // 1~3사이의 난수 출력. 3까지니까 3을 곱하고, 최소값은 1부터니까 1을 더하고 int로 casting. System.out.println((int)(d*(37-24+1..