전체 글
Day_05_Random_Quiz_04_Up & Down game
전적에서 다음으로 넘어가지지않음. System.exit(0); 코드 빼고 루프를 다시 짜야할 듯. 이걸 최단 기록만 기록할 수 있도록 만들어보기 import java.util.Scanner; // up & down game // 1~99까지 범위의 랜덤한 숫자를 맞추는 게임 // switch-case 문으로 만들 것 public class Quiz_04 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); //난수설정 1~99 int com = (int)(Math.random()*100+1); int result = 0; int count = 0; System.out.println("== Up & Down Game ..
Day_05_Random_Quiz_03
import java.util.Scanner; public class Quiz_03_answer { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while(true) { System.out.println("가위바위보 게임"); System.out.println("선택하세요. 1. 가위/ 2.바위 / 3.보 "); int player = Integer.parseInt(sc.nextLine()); int com = (int)(Math.random() * 3 + 1); System.out.println("결과"); switch(player) { case 1 : System.out.println("플레이어는 가위 냄"..
Day_05_Random_Quiz_02
import java.util.Scanner; public class Quiz_02 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while(true) { System.out.println("=== 동전 앞 뒤 맞추기 ==="); System.out.print("숫자를 입력해주세요 (1.앞면 / 2.뒷면) : "); int num = Integer.parseInt(sc.nextLine()); // 난수 1 또는 2 만들기 double i = Math.random(); if (num == (int)(i*2+1)) { System.out.println("맞췄습니다^^"); } else { System.out.pr..
Day_05_Random_Quiz_01
사용자가 원하는 랜덤 범위의 값 추출 /* 사용자가 원하는 랜덤 범위의 값 추출 */ public class Quiz_01 { public static void main(String[] args) { double rand = Math.random(); System.out.println("0~9까지의 랜덤 수 : " + (int)(rand*10)); System.out.println("1~10까지의 랜덤 수 : " + (int)(rand*(10-1+1)+1)); System.out.println("20~35까지의 랜덤 수 : " + (int)(rand*(35-20+1)+20)); System.out.println("0 또는 1 : " + (int)(rand*(1-0+1))); // 0~10 미만의 수는 n..
Day_05_Random_Exam_01
(Math.random() * (Y-X+1) + X) / 공식 외우기 public class Exam_01 { public static void main(String[] args) { // 0 ~ 1 사이의 임의 난수 (0.x) double rand = Math.random(); // 0.99999...9 / 0.00000...1 이 가장 크고 가장 작다 // 난수 출력 System.out.println(rand); // 난수의 범위를 조절하는게 필요 System.out.println((int)(rand * 10)); // 0~9까지 가능 // 주사위 만들 때는 System.out.println((int)(rand * 6)); // 0~5까지 가능 System.out.println((int)(rand *..
Day_04_Programming_220803-04_Homework2_1~n까지의 합 구하기
//무한루프 import java.util.Scanner; // 1~n까지의 합 구하기 public class Homework2 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("== 1 ~ n 까지의 합 구하기 =="); System.out.print("n 입력 : "); int n = Integer.parseInt(sc.nextLine()); int sum = 0; // 수학 공식 써서 푸는게 cpu 잘 안써서 더 효율적 // 반복문 안쓰고 풀어보기 n = 3 일 때, // 일단 1이 필요, + 2 + 3 = 이 결과값을 변수에 저장 // 모든걸 더할 int sum = 0;..
Day_04_Programming_220803-04_Homework_자판기 시뮬레이터
//무한루프 import java.util.Scanner; // 자판기 시뮬레이터 public class Homework { public static void main(String[] args) { int money = 3000; int numcola = 0; int numcider = 0; int numtea = 0; int sumcola = 1000; int sumcider = 800; int sumtea = 1500; //변수는 위에 저장되는 것임. 아래 연산작용 후에 여기에 저장되어 값이 변경됨. Scanner sc = new Scanner(System.in); while(true) { System.out.println("=== 자판기 시뮬레이터 ==="); System.out.println("음..
Day_04_Programming_220803-04_Variable
public class Variable { public static void main(String[] args) { // 변수의 종류 // [지역변수 / 매개변수] / 정적변수 / 멤버변수 // 우리가 이제까지 사용해온 변수는 지역변수 int a = 10; // 인트형 지역변수 a / 지역에서 사용할 수 있는 변수 / 자바에서는 {} 는 지역을 뜻함 int b = 20; // 바깥 지역에서 만들어진 변수는, 지역을 포함하는 쪽에서 만들어진 변수는 내부 지역에서 사용이 가능하다. { // 가 지역 /* int */ b = 20; // 자신이 속한 지역을 벗어날 수 없다. 생명주기를 다함. } System.out.println(b); // b라는 변수를 찾을 수 없다. / 12번째 줄에 변수 선언 하여서 ㄱ..