java的运算符

实际上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("准备补考吧!");
       }
}
准备补考吧!

 

posted @ 2018-03-16 23:45  浩族至尊  阅读(181)  评论(0编辑  收藏  举报