본문 바로가기

java23

Java 2-8) 계산기 만들기 / switch문 이용 / if문 이용 // 문제 풀기 전에 명확하게 기획 0. 변수선언 1. 입력 (1) 1번째 숫자 (2) 연산자 + - * / (3) 2번째 숫자 2. 연산 3. 결과 출력 // 가장 먼저 입력값 받기 위해 진행해야 할 것 import java.util.Scanner; ↑ Scanner sc = new Scanner(System.in); 0. 변수 선언 int number1, number2; String oper; int result = 0; 1. 입력 (1) 1번째 숫자 System.out.print("첫번째 수 = "); number1 = sc.nextInt(); (2) 연산자 + - * System.out.print("연산(+, -, *, /) = "); oper = sc.next(); (3) 2번째 숫자 Syste.. 2021. 12. 9.
Java 2-7) 조건문 switch // switch문 특징 - if문과 비슷 - 값이 명확해야 함 - 범위를 지정할 수 없음 (ex. >, 2021. 12. 9.
Java 2-6) 조건문 if, else, else if / 삼항 연산자 / equals 1. 조건문 if → 성립 if, else → 두 가지 중 하나 if, else if, else if, ... switch (사용빈도 낮음) 순환(loop) : 반복문 for while do while 제어자 : 순환을 제어 (독립 사용X) break continue 2. 조건문 if // 형식 if(조건) { 조건 → true/false 처리 } - 조건이 true면 처리, false면 넘어감 - 조건 : ==(같다), >, =, 0) { // true → 처리 System.out.println("number는 0보다 큽니다"); } if(number == 5) { System.out.println("number는 5입니다"); } if(number >= 5) { System.out.println("n.. 2021. 12. 8.
Java 2-5) Array 배열 1차원 / 2차원 // 배열 - 같은 자료형의 묶음 변수들 - 0 ~ Array.length-1 까지가 index number - 동적으로 할당한 후에 정적으로 사용 // 1차원 int Arr[] = new int[5]; // 0~4 0-0-0-0-0 행(row) int array[] = {1, 2, 3, 4, 5}; // 2차원 0-0-0-0-0 → 행 0-0-0-0-0 0-0-0-0-0 int array2[][] = new int[3][4]; → 3행에 원소의 개수 4개 int []array2[] = new int[3][4]; int [][]array2 = new int[3][4]; 0-0-0-0 0-0-0-0 0-0-0-0 // 2차원 배열의 초기화 int array2[][] = { {1, 2, 3, 4}, {5, .. 2021. 12. 8.