1. 程式人生 > >java的運算符

java的運算符

pub gpo class OS 關系運算 邏輯 輸入 blog oid

實際上java與c的運算符近乎一樣

1.關系運算符

public class laal {
    public static void main(String args[]) {
     if(5>2)
         System.out.println("返回值:"+(5>2));
     if(true)
         System.out.println("Hello java!");
     if((3+6)==(3-6))
         System.out.println("I like java!");
    }

}
返回值:true
Hello java
!

2.遞增與遞減運算符

public class Test {
    public static void main(String args[]) {
        int a = 3 , b = 3;
        
        System.out.print("a = "+a);
        System.out.println(" ,a++="+(a++)+" ,a="+a);
        System.out.print("b = "+b);
        System.out.println(" ,++b="+(++b)+" ,b="+b);
    }

}
a = 3 ,a++=3 ,a=4
b = 3 ,++b=4 ,b=4

3.邏輯運算符

public class logic {
        public static void main(String args[]) {
            int a = 56;       
            if((a<0)||(a>100))
                System.out.println("輸入的數據有錯誤!");
            if((a<60)&&(a>49))
                System.out.println(
"準備補考吧!"); } }
準備補考吧!

java的運算符