[ 관계연산자 ]


- 두값의 대소를 비교

 >, >=, ==(같다), <, <=, !=(같지않다.)

 

EX> 관계연산자

MyTest01.java

class MyTest01

{

    public static void main(String[] args) 

    {

        int a=10,b=20;

        boolean b1=a==b;

        boolean b2=a!=b;

        System.out.println("b1:"+b1);

        System.out.println("b2:"+b2);

    }

}

 

 



[ 논리연산자 ]

 

!(not) : 어떠한값이 참이면 거짓,거짓이면 참으로 바꿈

 

&& (and) : 대응되는 값이 모두 참이면 참,아니면 거짓

 

|| (or) : 대응되는 값이 모두 거짓이면 거짓,아니면 참

 

ex>

MyTest02.java

import java.util.Scanner;


class MyTest02

{

    public static void main(String[] args)  

    {

        Scanner scan=new Scanner(System.in);

        System.out.println("면접점수");

        int interview=scan.nextInt();

        System.out.println("영어점수");

 

        int eng=scan.nextInt();

 

        if(interview>=80 || eng>=90){

            System.out.println("당신은 합격입니다.");

        }else{

            System.out.println("당신은 불합격입니다.");

        }

    }

}


 




 [ 대입연산자 ] 

 

 

 연산자

 의미 

 a+=b

a = a + b 

 a-=b

a = a - b 

 a*=b

a = a * b 

 a/=b

a = a / b 


  

ex>

class MyTest03

{

    public static void main(String[] args)  

    {

        int a=3,b=4,c=5,d=6;

        a+=10;     //a=a+10;

        b-=5;      //b=b-5;

        c*=2;      //c=c*2;

        d/=3;      //d=d/3;

        System.out.println("a:"+a);    //a:13

        System.out.println("b:"+b);    //b:-1

        System.out.println("c:"+c);    //c:10

        System.out.println("d:"+d);    //d:2

    }

}


--------------------------------------

a:13

b:-1

c:10

d:2

 

 


ex>

class MyTest04

{

    public static void main(String[] args)  

    {

        int a=2;

        int b=5;

        int c=a|b;         //대응되는 비트값이 하나라도 참(1)이면 참

        int d=a&b;        //대응되는 비트값이 모두 참이면 참

        int e=a^b;        //대응되는 비트값이 서로 다르면 참

 

        System.out.println("c:"+c);

        System.out.println("d:"+d);

        System.out.println("e:"+e);

    }

}


-----------------------------


c:7

d:0

e:7


 




 [ 쉬프트 연산자 ]


 정수<<n : 정수를 좌측방향으로 n비트 이동

 정수>>n : 정수를 우측방향으로 n비트 이동



ex>

class MyTest05

{

    public static void main(String[] args) {

        int a=7;

        int b=a<<2;

        int c=a>>2;

        System.out.println("b:"+b);

        System.out.println("c:"+c);

    }

}





instanceof : ~타입의 객체인지 판별

                                                    

참조변수  instance of 클래스명       


ex>

class MyTest06

{

    public static void main(String[] args)  

    {

        String str="안녕";

        ////str이 String타입의 객체냐?

        if(str instanceof String)

        {

            System.out.println(str +"은 String 타입의 객체입니다.");

        }

        if(str instanceof Object){

            System.out.println(str +"은 Object 타입의 객체입니다.");

        }

    }

}




'JAVA' 카테고리의 다른 글

switch문  (0) 2014.09.12
IF문  (0) 2014.09.12
연산자  (0) 2014.09.12
변수, 자료형  (0) 2014.09.12
JDK다운로드, 설치, 이클립스 다운  (0) 2013.01.24

+ Recent posts