int형 배열 100칸 생성 후 100까지 저장하기
자바 프로그래밍/코드 2020. 2. 12. 23:03

public class Quiz_01 { public static void main(String[] args) { //int형 배열 100칸짜리를 생성하고, //각각의 칸에 1~100까지 저장하시오. int[] arr = new int[100]; //100칸짜리 배열을 만들고,그 배열의 주소를 저장하고 있을 배열참조함수 arr을 생성한다. for(int i=0;i

중복값 없이 랜덤 출력하기 - 카드섞기 기법
자바 프로그래밍/코드 2020. 2. 12. 23:01

//중복값 없이 랜덤 출력하기 //이중루프를 이용하여 하는 방법도 있음(필터링로직) public class Exam_04 { public static void main(String[] args) { /* * System.out.println((int)(Math.random()*5+1)); // 1~5 * System.out.println((int)(Math.random()*5+1)); // 1~5 * System.out.println((int)(Math.random()*5+1)); // 1~5 * System.out.println((int)(Math.random()*5+1)); // 1~5 * System.out.println((int)(Math.random()*5+1)); // 1~5 */ // ctr..

배열과 스왑(swap)기법
자바 프로그래밍/코드 2020. 2. 12. 23:01

//두 문자 서로 바꾸기 public class Exam_03 { public static void main(String[] args) { char[] A = new char[2]; char tmp; A[0]='A'; A[1]='B'; System.out.println(""+A[0]+A[1]); tmp=A[0]; A[0]=A[1]; A[1]=tmp; System.out.println(""+A[0]+A[1]); } }

입출력과 배열
자바 프로그래밍/코드 2020. 2. 12. 23:00

import java.util.Scanner; public class Exam_02 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); /* System.out.print("1번째 수 : "); int num1= Integer.parseInt(sc.nextLine()); System.out.print("2번째 수 : "); int num2= Integer.parseInt(sc.nextLine()); System.out.print("3번째 수 : "); int num3= Integer.parseInt(sc.nextLine()); System.out.println("num1 : " + num1); System.out...

배열참조변수
자바 프로그래밍/코드 2020. 2. 12. 23:00

import java.util.Scanner; public class Exam_01 { public static void main(String args[]) { int a=10; //int[] arr; //arr이라는 변수만 만들어진 것, 정확히는 Stack에다가 "배열의 주소를 저장한 참조변수"를 만든 것임. 배열의 본체는 Heap에 있다. 주소값을 Stack에 만들어진 변수 arr이 갖고 있는 것. //Heap에다가 뭔가 새로 만들겠습니다, Heap을 이용하겠습니다 할때의 용법은 new //new int[5]; //int형 변수 5개를 Heap에 만들겠다는 의미 //int b = new int[5]; // 에러가 남. 자료형이 안맞음. //String b = new int[5]; //에러가 남. 마찬..

Baskin Robbins 31 Game
자바 프로그래밍/코드 2020. 2. 11. 18:07

import java.util.Scanner; //Baskin Robbins 31 Game //1부터 시작, 31이 될때까지 서로 턴을 교대하여 숫자를 증가 //31을 먼저 외치는 사람이 지는 게임 public class Quiz_03 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int menu; int win=0; //플레이어 승리 int lose=0; //플레이어 패배 int player_oppo=0; //플레이어 횟수 int computer_oppo=0; // 컴퓨터 횟수 int number=0; //숫자 int i=0; //for문용 int int button=0; //31 나왔을때 종료용 버튼 //..