โœจ [JAVA]_23.02.26

โ€์ „ํฌ์ฃผยท2023๋…„ 2์›” 26์ผ
0

๐Ÿ’– ์‹œ์ž‘

  • 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
    ๐Ÿ”ฝ ide ์ž…๋ ฅ ๋ฌธ์žฅ (java)
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
    ๐Ÿ”ฝ ide ์ž…๋ ฅ ๋ฌธ์žฅ (java)
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) ? "๋‹ฌ๋ผ์š”" : "๊ฐ™์•„์š”";
      // ๊ฐ™์•„์š” 
      
    }
}

๐Ÿงก ํ€ด์ฆˆ #2

  • ํ€ด์ฆˆ
    ๐Ÿ”ฝ

๐Ÿ”ฝ 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 +  "ํ•ฉ๋‹ˆ๋‹ค.")
    
    
     
    }
}
profile
heejoojeon@daou.co.kr

0๊ฐœ์˜ ๋Œ“๊ธ€