Back end/Java 기본
-
SwitchCaseBack end/Java 기본 2023. 11. 14. 12:45
package chap_04; public class _04_SwitchCase { public static void main(String[] args) { // Switch Case // 석자에 따른 장학금 지급 // 1등 : 전액 장학금 // 2등 : 반액 장학금 // 3등 : 반액 장학금 // 그 외 : 장학금 대상 아님 // If Else 문을 이용 (여러 조건 또는 범위에해당하는 조건) int ranking = 4; // 등수 if (ranking == 1) { System.out.println("전액 장학금"); } else if (ranking == 2 || ranking == 3) { System.out.println("반액 장학금"); } else { System.out.println("..
-
Else ifBack end/Java 기본 2023. 11. 14. 12:44
package chap_04; public class _03_ElseIf { public static void main(String[] args) { // 조건문 ElseIf // 한라봉 에이드가 있으면 +1 // 또는 망고 주스가 있으면 +1 // 또는 아이스 아메리카노 +1 boolean hallabongAde = true; // 한라봉 에이드 boolean mangoJuice = true; // 망고 주스 if(hallabongAde) { System.out.println("한라봉 에이드 +1"); } else if (mangoJuice) { System.out.println("망고 주스 +1"); } else { System.out.println("아이스 아메리카노 +1"); } System.ou..
-
IF문Back end/Java 기본 2023. 11. 14. 12:41
package chap_04; public class _01_If { public static void main(String[] args) { // 조건문 If int hour = 15; // 오후 3시 // if 문 내에서 하나의 문장을 실행할 때는 { } 생략 가능 if (hour < 14) System.out.println("아이스 아메리카노 +1"); // if 문 내에서 2개이상의 문장을 실행할 때는 { } 생략 불가 if (hour < 14) { System.out.println("아이스 아메리카노 +1"); System.out.println("샷추가"); } System.out.println("커피 주문 완료 #1"); // 오후 2시 이전, 모닝 커피를 마시지 않은 경우? hour = 10..
-
문자열Back end/Java 기본 2023. 11. 14. 12:40
package chap_03; public class _01_String { public static void main(String[] args) { String s = "I like Java and python and C."; System.out.println(s); // 문자열의 길이 System.out.println(s.length()); // 29 // 대소문자 변환 System.out.println(s.toUpperCase()); // 대문자로 System.out.println(s.toLowerCase()); // 소문자로 // 포함 관계 System.out.println(s.contains("Java"));// 포함된다면 true System.out.println(s.contains("C#")..
-
삼항 연산자Back end/Java 기본 2023. 11. 14. 12:39
자바에서 삼항 연산자(Conditional Operator)는 세 개의 피연산자를 가지며, 조건에 따라 두 개의 표현식 중 하나를 선택하여 결과를 반환합니다. 삼항 연산자는 간단한 조건문을 표현할 때 유용하게 사용됩니다. package chap_02; public class _05_Operator5 { public static void main(String[] args) { // 삼항 연산자 // 결과 = (조건) ? (참의 경우 결과값) : (거짓의 경우 결과값) int x = 3; int y = 5; int max = (x > y) ? x : y; System.out.println(max); // 5 int min = (x < y) ? x : y; System.out.println(min); // 3..
-
논리 연산자Back end/Java 기본 2023. 11. 14. 12:38
자바에서 논리 연산자는 여러 조건을 조합하여 논리적인 결과를 얻는 데 사용됩니다. 주요 논리 연산자로는 AND(&&), OR(||), NOT(!)이 있습니다. package chap_02; public class _04_Operator4 { public static void main(String[] args) { // 논리 연산자 boolean 김치찌개 = true; boolean 계란말이 = true; boolean 제육볶음 = true; System.out.println(김치찌개 || 계란말이 || 제육볶음); // 하나라도 true 이면 true (괜찮은 식당) System.out.println(김치찌개 && 계란말이 && 제육볶음); // 모두 true 이면 true (최고의 식당) // And ..
-
비교 연산자Back end/Java 기본 2023. 11. 14. 12:35
자바에서 비교 연산자는 두 값 또는 표현식을 비교하는 데 사용됩니다. 비교 연산자는 불리언(boolean) 결과를 반환하며, 두 값이 서로 어떻게 관련되어 있는지를 검사합니다. 다음은 자바에서 사용되는 주요 비교 연산자입니다: package chap_02; public class _03_Operator3 { public static void main(String[] args) { // 비교 연산자 System.out.println(5 > 3); // 5 는 3 보다 크다(참이면 true , 거짓이면 false) System.out.println(5 >= 3); // 5는 3보다 크거나 같다 (true) System.out.println(5 >= 5); // 5 는 5보다 크거나 같다(true) Syste..