국비교육 4일차 JAVA : 연산자, Scanner
int x=5, y=5;
int z=++x; // ++x; x=x+1; x=6; z=x; z=6;
System.out.println("z => " + z); // z => 6
System.out.println("x => " + x); // x => 6
z=y++; // z=y; z=5; y++; y=y+1; y=6;
System.out.println("z => " + z); // z => 5
System.out.println("y => " + y); // y => 6
boolean bool = false;
System.out.println("bool : " + bool); // bool : false
System.out.println("!bool : " + !bool); // !bool : true
// --- && || 예시 ---
int c=10, d=20, e=30;
bool = (c > d) && (d < e) && (c == 3);
// fasle && skip && skip
// 어차피 시작부터 false 이기 때문에 뒤는 스킵
System.out.println("bool => " + bool); // bool => false
bool = (c > d) || (d < e) || (c == 3);
// false || true || skip
// true가 나오면 무조건 true 라서 이후는 스킵
System.out.println("bool => " + bool); // bool => true
// --- & | 예시 ---
int c=10, d=20, e=30;
bool = (c > d) & (d < e) & (c == 3);
// fasle & true & false
// & 하나는 스킵을 하지 못함. 따라서 속도가 상대적으로 느리게 됨.
System.out.println("bool => " + bool); // bool => false
bool = (c > d) | (d < e) | (c == 3);
// false | true | false
// | 하나는 스킵을 하지 못함.
System.out.println("bool => " + bool); // bool => true
int no = 1;
no += 5; // no = no + 5; 와 같은 것이다.
System.out.println("no="+no); // no=6;
no -= 3; // no = no - 3; 와 같은 것이다.
System.out.println("no="+no); // no=3;
no *= 5; // no = no * 5; 와 같은 것이다.
System.out.println("no="+no); // no=15;
no /= 5; // no = no / 5; 와 같은 것이다.
System.out.println("no="+no); // no=3;
no %= 4; // no = no % 3; 와 같은 것이다.
// %= 는 나머지를 뜻한다.
System.out.println("no="+no); // no=3;
int num1 = 7, num2 = 10;
int num3 = (num1 > num2)? num1:num2;
System.out.println("num3 => " + num3); // num3 => 10
import java.util.Scanner;
Scanner scan = new Scanner(System.in);
scan.close();
System.out.print("문장을 입력하세요 => ");
String inputStr = scan.nextLine();
System.out.println(">> 입력한 문장 => " + inputStr);
System.out.print("첫번째 정수를 입력하세요. => ");
int inputNum_1 = scan.nextInt();
scan.nextLine();
System.out.println(">> 첫번째 입력한 정수 " + inputNum_1);
System.out.print("첫번째 실수를 입력하세요. => ");
double inputDbl_1 = scan.nextDouble();
scan.nextLine();
System.out.println(">> 첫번째 입력한 실수 " + inputDbl_1);
System.out.print("첫번째 단어를 입력하세요. => ");
String inputWord_1 = scan.next();
scan.nextLine();
System.out.println(">> 첫번째 입력한 단어 : " + inputWord_1);