본문 바로가기
반응형

학습/JAVA24

4. 반복문(for문, while문, do-while문 - for 문 public class ForExam { public static void main(String[] args) { // (초기화식; 조건식; 증감식) // 조건식이 true이면 중괄호 블럭 실행 // 순서: 초기화식 - 반복구간[조건식 - 실행문 - 증감식] for(int i=0; i 2022. 9. 30.
4. 조건문(if문, switch문) - if ~ else 사용 public class IfExam2 { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print(">>점수 입력 "); int score = scanner.nextInt(); ifElseTest(score); } private static void ifElseTest(int score) { if(score >= 90) { System.out.println("90이상"); System.out.println("A"); } else { System.out.println("90미만"); System.out.println("B"); } } } 보기와 같은 코드일경우.. 2022. 9. 29.
3. 연산자(3) - Infinity, NaN 여부 체크 메소드 - 해당 래퍼클래스에 isInfinite(), isNaN() 메소드를 제공함 isInfinite() : 전달된 매개변수가 Infinity이면 true 반환 isNaN() : 전달된 매개변수가 NaN이면 true 반환 public class InfinityAndNaNCheck { public static void main(String[] args) { double infinity1 = 5/0.0; double nan1 = 5%0.0; System.out.println(Double.isInfinite(infinity1)); System.out.println(Double.isNaN(nan1)); float infinity2 = 5/0.0f; float nan2 =.. 2022. 9. 29.
3. 연산자(2) - 메소드 public class MethodExample { // main메소드 // String[] args 매개변수 // (매개변수 타입) (매개변수이름) // 매개변수 = 인수 = 인자 = 파라미터 public static void main(String[] args) { System.out.println("메인메소드를 실행함"); String greeting = "안녕?"; // 문자열 데이터 System.out.println("proceed메소드를 호출합니다"); proceed(greeting); System.out.println("메인메소드 끝"); } public static void proceed(String message) { // message = "안녕?" 할당됨 System.out... 2022. 9. 28.
반응형