본문 바로가기

JAVA39

디버그(Debug) package loop_for; public class Debug { public static void main(String[] args) { // 디버그 기능 // 브래이크 포인트(시작지점) : Ctrl + Shift + b or 좌측 번호왼쪽 더블클릭 // 디버그 시작 : f11 // f6으로 점진적으로 코드의 진행을 볼 수 있다. // 디버그 중단 : Ctrl + f2 or 우측 상단에 perspective 설정 int sum = 0; for (int i = 1; i 2022. 7. 21.
while문 예제(2) package loop_while; import java.util.Random; import java.util.Scanner; public class LoopWhileQuiz2 { public static void main(String[] args) { // Quiz1 // 1 ~ 6 주사위 수 3개를 컴퓨터와 유저가 무작위로 부여받아 겨루는 게임 Scanner sc = new Scanner(System.in); Random rand = new Random(); int com = 0, total = 0, win = 0, lose = 0, draw = 0; int sel, diceTotal = 0, myDice, money = 10000, bat = 0; char sel2 = 'Y'; while (true.. 2022. 7. 21.
while문 예제(1) package loop_while; import java.util.Random; import java.util.Scanner; public class LoopWhileQuiz { public static void main(String[] args) { // 1 ~ 100사이의 수 중 랜덤하게 부여된 수를 맞추는 게임 // ex) 사용자의 입력값이 랜덤수보다 낮을경우 up을 출력, 낮을 경우 down을 출력 Random rand = new Random(); Scanner sc = new Scanner(System.in); int sel, user = 101, com, cnt = 101, tmpCnt; while (true) { System.out.print("=== Up & Down Game ===\n1... 2022. 7. 21.
배열 예제(3) package arrays; import java.util.Random; public class ArrayQuiz3 { public static void main(String[] args) { // Quiz2 // 로또번호를 자동 출력해주는 코드 작성 int[] lotto = new int[6]; Random rand = new Random(); // 로또 배열에 랜덤값 생성과 동시에 중복되는 수를 검사하고 있다. for (int cnt1 = 0; cnt1 < lotto.length; cnt1++) { lotto[cnt1] = rand.nextInt(45) + 1; for (int cnt2 = 0; cnt2 < cnt1; cnt2++) if (lotto[cnt1] == lotto[cnt2]) { cnt1.. 2022. 7. 20.