카테고리 없음

19-03-14_TIL

Doohwancho 2019. 3. 14. 23:34
package Java_book;
public class IfStatement {
public static void main(String[] args) {
//조건연산자 ?는 조건식, 식1, 식2가 필요로 하는 삼항 연산자에 쓰이며, 사용처는 다음과 같다.
int x = 12;
int y = 13;
boolean result = (x > y) ? true : false;
System.out.println(result);
//밑의 if else문과 같다.
//특이점은 파이썬과는 달리 int result2를 선언해 주어야 한다.
int result2;
if (x > y)
result2 = x;
else
result2 = y;
System.out.println(result2);
//조건연산자를 한번에 여러번 사용할 수 도 있다.
Object result3 ;
int z = -2;
result3 = z > 0 ? true: (z == 0 ? 0 : false);
System.out.println(result3);
}
}
결과물

true 14 true 14 else-if문은 이렇게 처리한다. false else-if문은 이렇게 처리한다. false















package Java_book;
public class Unicode {
public static void main(String[] args) {
char ch = 'A';
int code = (int)ch;
System.out.printf("%c = %d(%#X) %n", ch, code, code);
char hch = '가';
System.out.printf("%c=%d(%X)%n", hch, (int)hch, (int)hch);
//\n means enter
System.out.println("\n");
//\' or \" can be used to illustrate quotation marks
System.out.println("\"Hello\"");
System.out.println("\'");
System.out.println("\\");


}
}


결과물

A = 65(0X41) 가=44032(AC00) "Hello" ' \