공책

연산자 본문

웹 개발/Java

연산자

QTHoney 2013. 8. 26. 11:35

package ex2;


public class Ex1 {

public static void main(String[] args) {

//연산자

//1. 최고 연산자 : . , ()

//2. 증감 연산자 : ++, -- 

//3. 산술 연산자 : +, -, *, /, %

//4. 시프트 연산자 : >>, <<, >>>

//5. 비교 연산자 : >, <, >=, <=, ==, !=

//6. 비트 연산자 : &, |, ^, ~

//8. 조건 연산자 : ?, :

//9. 대입 연산자 : =, *= , /=, %=, +=, -=

//산술연산자

//산술연산자는 4칙연산과 나머지를 구하는 연산자로 나뉨

int n1, n2, n3;

n1 = 20;

n2 = 7;

n3 = n1 + n2;

System.out.println("n3 = " + n3);

//대입연산자

//특정 값을 변수에 전달하여 기억시킬 때 사용하는 연산자

int a1 = 10;

int a2 = 7;

System.out.println(a1 + ", " + a2);

int a3 = 13;

int a4 = 15;

System.out.println("a3 += a4 = " + (a3 + a4));

//비교연산자

//비교 연산자는 변수나 상수의 값을 비교하여 참과 거짓을 판단하는 연산자.

//그러므로 결과값은 반드시 true false로만 반환

int b1 = 10;

int b2 = 20;

boolean result = b1 < b2;

System.out.println("b1 < b2 : " + result);

result = b1 == b2;

System.out.println("b1 == b2 : " + result);

result = b1 != b2;

System.out.println("b1 != b2 : " + result);

//논리연산자

//비교연산자를 통한 연산이 2개 이상 필요할 때 사용

int myAge = 30;

int limit = 35;

boolean result2 = (limit = myAge) >= 5 && myAge>=30;

System.out.println(result2);

int c1 = 10;

int c2 = 20;

boolean result3 = (c1 += 10) >20 || (c2 - 10) ==11;

System.out.println("||연산결과 : " + result3);

//!은 not의 뜻

System.out.println("!연산결과 : " + !result3);

}

}



'웹 개발 > Java' 카테고리의 다른 글

if else 문  (0) 2013.08.26
if 문  (0) 2013.08.26
형변환  (0) 2013.08.26
기본 자료형 실습  (0) 2013.08.26
기본 자료 형  (0) 2013.08.26
Comments