관리 메뉴

nalaolla

연산자 정리2 본문

JAVA/2. Operator

연산자 정리2

날아올라↗↗ 2015. 12. 1. 01:53
728x90
  1. package test.com;
  2.  
  3. public class Test01Operator2 {
  4.  
  5.     public static void main(String[] args) {
  6.         // TODO Auto-generated method stub
  7.         System.out.println("Operator2...");
  8.        
  9.         //5. 비교연산자 : ==, !=, >, <, >= <=
  10.         //비교연산의 결과는 boolean(true, false)
  11.         System.out.println(10 == 10);
  12.         System.out.println(10 != 10);
  13.         System.out.println(10 > 10);
  14.         System.out.println(10 < 10);
  15.         System.out.println(10 >= 10);
  16.         System.out.println(10 <= 10);
  17.        
  18.         boolean bool = 10 <= 10;
  19.         System.out.println(bool);
  20.         bool = true == false;
  21.         System.out.println(bool);
  22.         bool = true | false;
  23.         System.out.println(bool);
  24.        
  25.         //System.out.println(15 << 1);
  26.        
  27.         //6. shift 연산자 >>, <<, >>>
  28.         //8(1000) >> 2 : 0010
  29.         System.out.println(8 >> 2);  //우측이동
  30.         System.out.println(2 << 2);  //좌측이동
  31.         System.out.println(-8 >> 2);    //음수도가능
  32.         System.out.println(-8 >>> 2);   //결과가 반드시 양수
  33.         System.out.println("======================");
  34.         System.out.println(Integer.toBinaryString(-80000000 ));
  35.         System.out.println(Integer.toBinaryString(-80000000 >> 2));
  36.         System.out.println(Integer.toBinaryString(-80000000 >>> 2));
  37.         System.out.println(Integer.toBinaryString(-8));
  38.         System.out.println(Integer.toBinaryString(-8 >>> 2));
  39.         System.out.println("======================");
  40.        
  41.         //7. 논리자연산 &&, ||
  42.         System.out.println(true && false);
  43.         System.out.println(true || false);
  44.         System.out.println(5>3 || false);   //전위가 참일경우 후위계산무시
  45.         System.out.println(5>3 | false);    //전위계산이 참이어도 후위계산진행
  46.        
  47.         //8. 삼항연산자 : 항 3개
  48.         //비교,논리 ? 참값 : 거짓값
  49.         int result = 5==5 ? 100 : 50;
  50.         System.out.println("result : " + result);
  51.         System.out.println( 5==5 ? 100 : 50);
  52.         System.out.println( 5!=5 ? 100 : 50);
  53.        
  54.         System.out.println( 5!=5 ? "100" : "50");
  55.         String str = 5>5 ? "가나다" : "라마바";
  56.         System.out.println(str);
  57.        
  58.         boolean bool2 = true && false ? true : false;
  59.         System.out.println(bool2);
  60.        
  61.         int korScore = 90;
  62.         int engScore = 70;
  63.         int mathScore = 70;
  64.        
  65.         int totalScore = korScore + engScore + mathScore;
  66.         double totalAvg = totalScore  / 3;
  67.        
  68.         //거짓일때 재 삼항연상 실행
  69.         String str2 = totalAvg >= 90 ? "A Class" : totalAvg >= 80 ? "B Class" : totalAvg >= 70 ? "C Class" : "D Class";
  70.        
  71.         System.out.println("Your Class : " + str2);
  72.        
  73.        
  74.        
  75.         //9. 기타연산   . , () new
  76.         // '.' : 소속. dot기준으로 우측에 있는것은 좌측에 소속된다.
  77.         // ',' : 열거,나열
  78.         // '()' : 우선연산
  79.         // 'new' : 생성연산자(객체, 배열) : 주소를 할당한다.
  80.         // '...' : 배열
  81.         // ':' : 위치지정
  82.         // '!' : 부정, 반대
  83.        
  84.         /**
  85.          * javadoc주석
  86.          */
  87.  
  88.     }
  89.    
  90.    
  91. }


728x90

'JAVA > 2. Operator' 카테고리의 다른 글

자판기 프로그램1  (0) 2015.12.01
연산자 정리1  (0) 2015.12.01