반응형
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Q1_Q1 { | |
public static void main(String[] args) { | |
// Exercise02.java 후행연산자 선행연산자 이해 | |
int x = 13; | |
int y = 20; | |
int z = (++x) + (y--); | |
System.out.println(z); | |
// Exercise03.java 삼항연산자 이해 | |
int score = 85; | |
String result = (!(score > 90))? "가" : "나"; | |
System.out.println(result); | |
// Exercise04.java 남은 연필 수와 나눠가질 수 있는 연필수 | |
int penciles = 534; | |
int student = 30; | |
/* 학생 한 명이 가지는 연필 수 */ | |
int pencilsPerstudent = (penciles / student); | |
System.out.println("학생 당 연필 갯수는 " + pencilsPerstudent + " 자루"); | |
/* 남은 연필 수 */ | |
int pencilsLeft = (penciles % student); | |
System.out.println("나눠주고 남은 연필 갯수는 " + pencilsLeft + " 자루"); | |
// Exercise05.java 산술연산자 | |
int Value = 356; | |
System.out.println(Value / 100 * 100); | |
// Exercise06.java 사다리꼴 계산 | |
int lenthTop = 5; | |
int lenthBottom = 10; | |
int heigh = 7; | |
double area = ((lenthTop + lenthBottom)* heigh)*0.5; | |
System.out.println("사다리꼴 넓이: " + area); | |
// Exercise07.java 논리연산자 | |
int xx = 10; | |
int yy = 5; | |
System.out.println((xx>7) && (yy <= 5)); // 출력 결과: true && true = true | |
System.out.println((xx%3 == 2) || (yy%2 != 1)); // 출력 결과: false && false = | |
// Exercise08.java NaN 검사 | |
double xxx = 5.0; | |
double yyy = 0.0; | |
double zzz = xxx % yyy; | |
if(Double.isNaN(zzz)) { // 나눌 수 없다 | |
System.out.println("0.0으로 나눌 수 없는 값입니다."); | |
} else { // 나눌 수 있다 | |
double result01 = zzz +10; | |
System.out.println("결과: " + result01); | |
} | |
} | |
} |
[실행 결과]
반응형
'공부 > 개발노트' 카테고리의 다른 글
[이것이 자바다] whileKeyControlExample 예제 급감속 급가속 추가 소스 (0) | 2018.10.30 |
---|---|
[이것이 자바다] if문과 ifelse문 변형 (0) | 2018.10.28 |
[JAVA] 삼항연산자 사용법 (0) | 2018.10.28 |
jQuery 함수 선언 방법 (0) | 2018.04.09 |
업힙(UpHeap) 알고리즘 정의하기 (0) | 2016.09.29 |