전체 글
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번째 줄에 변수 선언 하여서 ㄱ..
Day_04_Programming_220803-04_ExceptionHandler
import java.util.Scanner; public class ExceptionHandler { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int num = 0; while(true) { // 제대로 입력할 때까지 반복. 반복 입력이 필요할 때만 while true System.out.print("숫자 입력 : "); try { // 신규문법. 예외처리기법. try 시도해라 /* int // 변수 선언 */ num = Integer.parseInt(sc.nextLine());// 에러가 발생 될 것으로 예상되는 지점을 예외처리한다. // 에러가 발생하는 즉시 바로 catch로 건너뜀. // (아래 1 ..
Day_04_Programming_220803-04_Exam_01
import java.util.Scanner; public class Exam_01 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("Apple 을 입력하세요. : "); String msg = sc.nextLine(); // 참조 자료형임. 문자가 들어가있는게 아니라 주소값이 들어가있다. System.out.println("정답입니다."); if(msg.equals("Apple")) { // 알파벳 하나하나 비교가 필요함 msg.equals("Apple") 이렇게 적어야함 // 문자열 비교할 때는 msg == "Apple" 가 아니다. System.out.println("정답..
Day_04_Programming_220803-04_계산기_답안
import java.util.Scanner; public class Calc_answer { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int num1 = 0; int num2 = 0; while(true) { System.out.println("=== 계산기 프로그램 ===\r\n"); System.out.print("연산자 입력 (+,-,*,/,q[종료]) : "); String oper = sc.nextLine(); if (oper.equals("q")) { System.out.println("계산기를 종료합니다."); System.exit(0); } /*else if(!oper.equals("+") ..
Day_04_Programming_220803-04_계산기
import java.util.Scanner; public class Calc { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int sum = 0; int num1 = 0; int num2 = 0; while(true) { System.out.println("=== 계산기 프로그램 ===\r\n"); System.out.print("연산자 입력 (+,-,*,/,q[종료]) : "); String calc = sc.nextLine(); if(calc.equals("q")) { System.out.println("\r\n계산기 프로그램을 종료합니다."); System.exit(0); //} else if(calc..
Day_04_Programming_220803-04_ATM 시뮬레이터_답안
import java.util.Scanner; public class ATM_answer { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int money = 0; // 잔액 변수 while(true) { System.out.println("***ATM 시뮬레이터***"); System.out.println("1. 잔액조회"); System.out.println("2. 입금하기"); System.out.println("3. 출금하기"); System.out.println("4. 종료하기"); System.out.print(">> "); int menu = Integer.parseInt(sc.nextLine())..
Day_03_Control_220802-3_Homework_ATM 시뮬레이터
import java.util.Scanner; public class Study { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while(true) { System.out.println("***ATM 시뮬레이터***"); System.out.println("1. 잔액조회"); System.out.println("2. 입금하기"); System.out.println("3. 출금하기"); System.out.println("4. 종료하기"); System.out.print(">> "); int select = Integer.parseInt(sc.nextLine()); int money = 0; int moneya..
Day_03_Control_220802-3_Homework
import java.util.Scanner; public class Homework { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("어느날 당신은 여유를 즐기며 침대위에서 책을 보고 있었습니다.\r\n" + "그런데...!! 갑자기 나타난 커다란 벌레.\r\n" + "당신은 이 벌레를 보고 어떻게 하시겠습니까?\r\n" + "======\r\n" + "1. 살충제를 듬뿍 뿌려버린다.\r\n" + "2. 벌레를 못본 적 하고 그냥 책을 읽는다.\r\n" + "3. 집이 떠나가라 소리를 지른다.\r\n" + "4. 무엇이든 손에 들고 벌레를 때려잡는다."); System.out..