목록BACKEND/JAVA (14)
Salangdung_i의 기록
![](http://i1.daumcdn.net/thumb/C150x150.fwebp.q85/?fname=https://blog.kakaocdn.net/dn/bK4xMe/btrmvewYW1o/KK2OoYYyU5uIIVd8aq9YJ0/img.png)
배열의 길이 변경하기 더 큰 배열을 새로 생성한다. 기존 배열의 내용을 새로운 배열에 복사한다. public class ArrayEx3 { public static void main(String[] args) { int[] arr = new int[5]; for(int i=0;i
![](http://i1.daumcdn.net/thumb/C150x150.fwebp.q85/?fname=https://blog.kakaocdn.net/dn/bD1Die/btrmxkKgPIC/uifsKx50P76OvBRQkkcKkk/img.png)
array로 만드는 로또 프로그램 public void lotto() { Scanner sc = new Scanner(System.in); Random r = new Random(); boolean bool = true; int[] lottoNum = new int[6]; int[] comNum = new int[6]; int num = 0; int result = 0; System.out.println("==== 로또 프로그램 ===="); // 컴퓨터가 로또 돌리는 코드 for (int i = 0; i
![](http://i1.daumcdn.net/thumb/C150x150.fwebp.q85/?fname=https://blog.kakaocdn.net/dn/dwoZgY/btrmrutAx2K/1CyMjyKxCjnp2sMPXxfKt1/img.png)
array 게임 public void motel() { boolean bool = true; Scanner sc = new Scanner(System.in); String[] room = new String[10]; for (int i = 0; i "); int sel = sc.nextInt(); switch (sel) { case 1: System.out.print("몇번방에 ..
![](http://i1.daumcdn.net/thumb/C150x150.fwebp.q85/?fname=https://blog.kakaocdn.net/dn/bo8wAr/btrmCDu1Ssn/tBsV2x84rnUpa99I6cOtK1/img.png)
이번에는 Array에 대한 공부를 해볼 차례이다. Array이란 배열 : 같은 타입의 여러 변수를 하나의 묶음으로 다루는 것 배열 선언 :: int [] arr; int [] arr = new int[5]; int [] arr = {1, 2, 3, 4, 5}; -> 길이가 5인 배열이 생성 arr[0] = 1, arr[1]=2, arr[2]=3, arr[3]=4, arr[4]=5 "마지막 번호는 길이-1" 배열을 사용하는 이유? -> 여러개의 같은 타입 데이터를 한번에 선언이 가능 -> 연속적으로 사용이 가능 (제어문으로 사용이 가능 ) String [] strArr1 = { "딸기", "복숭아", "키위", "사과", "바나나"} String 배열, 변수명을 strArr1 이라 명명한 후 String ..
![](http://i1.daumcdn.net/thumb/C150x150.fwebp.q85/?fname=https://blog.kakaocdn.net/dn/bEjdot/btrmtgBSGmH/lkG120Ki8W1NFNBi9hmMOK/img.png)
이번에는 난수 Random에 대한 공부를 해볼 차례이다. Random이란? 자바에서 난수를 생성하는 방법으로 Random r = new Random(); // 랜덤객체 생성 int i =r.nextInt(숫자); // i에 랜덤 숫자 대입 r.nextInt(숫자);에서 숫자에 들어가는 수를 5라고하면 0부터 4까지 총 5개의 정수가 랜덤으로 뽑히는 것이다. 가독성 좋게 r.nextInt(숫자)+1; 로 하여 1부터 내가 max값으로 지정하고 싶은 수까지 랜덤으로 뽑히게끔 만들어 사용한다. 먼저 r.nextInt(숫자) 를 이용해서 지정한 숫자사이에서 랜덤수가 추출되는지 확인해보자. int num = r.nextInt(100); // 0~99사이의 랜덤수 0~9범위의 랜덤수 추출 int num1 = r.n..
![](http://i1.daumcdn.net/thumb/C150x150.fwebp.q85/?fname=https://blog.kakaocdn.net/dn/c9ym2j/btrmtfwabIG/x7CFiVf9BcpXmRdXfKibaK/img.png)
이번에는 그동안 배웠던 반복문에 대한 예제를 풀어보는 시간이다. 이전 내용이 기억나지 않는다면..! https://salangdung.tistory.com/17 JAVA :: For문 이번에는 for문에 대한 공부를 해볼 차례이다. for문이란 for( 초기식 ;조건식 ;증감식) { 실행코드 } 로 구성되어 사용가사 원하는 만큼 명령들을 여러번 실행하는 제어문 으로 특정 조건이 만족되는 동안 명령을.. salangdung.tistory.com https://salangdung.tistory.com/19 JAVA 04 :: 중첩 for문 이번에는 중첩 for문에 대한 공부를 해볼 차례이다. for문이란 for( 초기식 ;조건식 ;증감식) { 실행코드 } 로 구성되어 사용가사 원하는 만큼 명령들을 여러번 실..
![](http://i1.daumcdn.net/thumb/C150x150.fwebp.q85/?fname=https://blog.kakaocdn.net/dn/b5kbyM/btrmzjDQsKX/eO83odzKxUVpntolpeErFK/img.png)
public void main() { Scanner sc = new Scanner(System.in); Random r = new Random(); boolean bool = true; int count = 0; // 변수선언을 여기서 해줘야 2.GameScore에서 사용할수있음 int record = 100; while (bool) { System.out.println(" === Up & Down Game === "); System.out.println("1. GameStart"); System.out.println("2. GameScore"); System.out.println("3. End Game"); System.out.print("선택 > "); int sel = sc.nextInt(); sw..
![](http://i1.daumcdn.net/thumb/C150x150.fwebp.q85/?fname=https://blog.kakaocdn.net/dn/d7BBDN/btrmyjjOWPB/QpnthqiBo1jQZ8z6IqI8hK/img.png)
public class dice { public void main() { Scanner sc = new Scanner(System.in); Random r = new Random(); boolean bool = true; while (bool) { System.out.println(" === Dice Game === "); System.out.println("1. GameStart"); System.out.println("2. GameScore"); System.out.println("3. End Game"); System.out.print("선택 > "); int sel = sc.nextInt(); switch (sel) { case 1: // 실제 게임 로직 작성 int comNum = 0; int ..
![](http://i1.daumcdn.net/thumb/C150x150.fwebp.q85/?fname=https://blog.kakaocdn.net/dn/IT79K/btrmzMeH44E/hsoOEtTI2eeaQomKmkO2Sk/img.png)
public void main() { Scanner sc = new Scanner(System.in); Random r = new Random(); boolean bool = true; int win = 0; // 승리체크용 int lose = 0; // 패배체크용 while (bool) { System.out.println(" === baskinRobbins31 Game === "); System.out.println("1. GameStart"); System.out.println("2. GameScore"); System.out.println("3. End Game"); System.out.print("선택 > "); int sel = sc.nextInt(); switch (sel) { case 1:..