new package
-> chap_02
chap_02
-> new
-> new java class
-> _01_Operator1
๐ฝ ide ์ ๋ ฅ ๋ฌธ์ฅ (java)
package chap_02;
public class _01_Operator1 {
public static void main(String[] args) {
// ์ฐ์ ์ฐ์ฐ์
// ์ผ๋ฐ ์ฐ์ฐ
System.out.println(4 + 2); //6
System.out.println(4 - 2); //2
System.out.println(4 * 2); //8
System.out.println(4 / 2); //2
System.out.println(5 / 2); // 2.5 -> 2 (์ ์ ๊ฐ ์ฐ์ฐ์ ์ ์๊ฐ ๋ฐํ)
System.out.println(2 / 4); // 0.5 -> 0
System.out.println(4 % 2); // ๋๋จธ์ง ์ฐ์ฐ ->0
System.out.println(5 % 2); // 1
// ์ฐ์ ์์ ์ฐ์ฐ
System.out.println(2 + 2 * 2); // 6
System.out.println((2 + 2) * 2); //8
System.out.println(2 + (2 * 2)); //6
System.out.println((2 + 2) * 2); //8
// ๋ณ์ ์ด์ฉ ์ฐ์ฐ
int a = 20;
int b = 10;
int c;
c= a + b;
System.out.println(c); // 30
c= a - b;
System.out.println(c); // 10
c= a * b;
System.out.println(c); // 200
c= a / b;
System.out.println(c); // 2
c = a % b
System.out.println(c); // 0
}
}
๐ฝ ide ์ ๋ ฅ ๋ฌธ์ฅ (java)
package chap_02;
public class _01_Operator1 {
public static void main(String[] args) {
// ์ฆ๊ฐ ์ฐ์ฐ ++, --
// ์ฆ๊ฐ
int val;
val = 10;
System.out.println(val); // 10
//val = val + 1;
val++; // val ์ํ ํ val + 1 ์ํ
++val; // val + 1 ๋จผ์ ์ํ
System.out.println(++val); // 11
System.out.println(val); // 11
val = 10;
System.out.println(val); // 10
System.out.println(val++); // 10
System.out.println(val); // 11
// ๊ฐ์
System.out.println(val); // 10
System.out.println(--val); // 9
System.out.println(val); // 9
val =10;
System.out.println(val); // 10
System.out.println(val--); // 10
System.out.println(val); // 9
// ์ํ ๋๊ธฐ๋ฒํธ ํ
int waiting = 0;
System.out.println("๋๊ธฐ ์ธ์: " + waiting++); // ๋๊ธฐ ์ธ์ 0
System.out.println("๋๊ธฐ ์ธ์: " + waiting++); // ๋๊ธฐ ์ธ์ 1
System.out.println("๋๊ธฐ ์ธ์: " + waiting++); // ๋๊ธฐ ์ธ์ 2
System.out.println("์ด ๋๊ธฐ ์ธ์: " + waiting); // ์ด ๋๊ธฐ ์ธ์: 3
}
}
chap_02
-> new
-> new java class
-> _02_Operator2
๐ฝ ide ์ ๋ ฅ ๋ฌธ์ฅ (java)
package chap_02;
public class _02_Operator2 {
public static void main(String[] args) {
// ๋์
์ฐ์ฐ์
int num = 10;
num = num + 2;
System.out.println(num); // 12
num = num -2;
System.out.println(num); //10
num = num * 2
System.out.println(num); // 20
num= num/2;
System.out.println(num); // 10
num = num % 2
System.out.println(num); // 0
//๋ณตํฉ ๋์
์ฐ์ฐ์
num = 10;
// num = num + 2;
num += 2;
System.out.println(num); // 12
// num = num -2;
num -= 2;
System.out.println(num); // 10
//num = num * 2
num *= 2;
System.out.println(num); // 20
//num= num/2;
num /= 2;
System.out.println(num); // 10
//num = num % 2
num %= 2;
System.out.println(num); // 0
}
}
chap_02
-> new
-> new java class
-> _03_Operator3
๐ฝ ide ์ ๋ ฅ ๋ฌธ์ฅ (java)
package chap_02;
public class _03_Operator3 {
public static void main(String[] args) {
// ๋น๊ต ์ฐ์ฐ์
System.out.println(5 > 3); // 5๋ 3๋ณด๋ค ํฌ๋ค//์ฐธ์ด๋ฉด true, ๊ฑฐ์ง์ด๋ฉด false (boolean ๊ฐ ๋ฐํ)
System.out.println(5 >= 3); // true
System.out.println(5 >= 5); // true
System.out.println(5 >= 7); // false
System.out.println(5 < 3); //false
System.out.println(5 <= 3); // false
System.out.println(5 == 5); // true
System.out.println(5 == 3); // false
System.out.println(5 != 5); // false
System.out.println(5 != 3); // true
}
}
chap_02
-> new
-> new java class
-> _04_Operator4
package chap_02;
public class _04_Operator4 {
public static void main(String[] args) {
// ๋
ผ๋ฆฌ ์ฐ์ฐ์
boolean ๊น์น์ฐ๊ฐ = false;
boolean ๊ณ๋๋ง์ด = true;
boolean ์ ์ก๋ณถ์ = true;
System.out.println(๊น์น์ฐ๊ฐ || ๊ณ๋๋ง์ด || ์ ์ก๋ณถ์); // or// ํ๋๋ผ๋ true ์ด๋ฉด true // true
System.out.println(๊น์น์ฐ๊ฐ && ๊ณ๋๋ง์ด &&์ ์ก๋ณถ์);// and// ๋ชจ๋ true์ด๋ฉด true// false
// and ์ฐ์ฐ
System.out.println(5 > 3) && (3 > 1);
//true // and์ฐ์ฐ ์ํ
System.out.println(5 > 3) && (3 < 1);
// false
// or ์ฐ์ฐ
System.out.println(5 > 3) || (3 > 1);
//true
System.out.println(5 > 3) || (3 < 1);
// true
System.out.println(5 < 3) || (3 < 1);
// false
// System.out.println((1<3<5) ๋ถ๊ฐ๋ฅ
// System.out.println((1<3&&<5) ๊ฐ๋ฅ
// ๋
ผ๋ฆฌ ๋ถ์ ์ฐ์ฐ์
System.out.println(!true); // false
System.out.println(!false); // true
System.out.println(5==5); // true
System.out.println(!(5 == 5)); // false
System.out.println(!(5 == 3)); // true
}
}
chap_02
-> new
-> new java class
-> _05_Operator5
package chap_02;
public class _05_Operator5 {
public static void main(String[] args) {
// ์ผํญ ์ฐ์ฐ์
// ๊ฒฐ๊ณผ = (์กฐ๊ฑด)? (์ฐธ์ ๊ฒฝ์ฐ ๊ฒฐ๊ณผ ๊ฐ) : (๊ฑฐ์ง์ ๊ฒฝ์ฐ ๊ฒฐ๊ณผ๊ฐ)
int x = 5;
int y = 3;
int max = (x>y) ? x : y;
System.out.println(max); // 5
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
x = 3;
y = 5;
boolean b = (x == y) ? true : false;
System.out.println(b); // false
x = 3;
y = 3;
boolean b = (x == y) ? true : false;
System.out.println(b); //true
int x = 3;
int y = 5;
string s = (x != y) ? "ํค๊ฐ" : "๊ฐ์์";
// ๋ฌ๋ผ์
int x = 3;
int y = 3;
string s = (x != y) ? "๋ฌ๋ผ์" : "๊ฐ์์";
// ๊ฐ์์
}
}
๐ฝ ide ์ ๋ ฅ ๋ฌธ์ฅ (java)
package chap_02;
public class _Quiz_02_.java {
public static void main(String[] args) {
int height = 115
string s = (height >= 120) ? "ํ์น ๊ฐ๋ฅ" : "ํ์น ๋ถ๊ฐ๋ฅ"
System.out.println("ํค๊ฐ" +height+ "cm ์ด๋ฏ๋ก " + s + "ํฉ๋๋ค.")
}
}