码迷,mamicode.com
首页 > 编程语言 > 详细

java 运算符

时间:2016-06-24 17:31:28      阅读:177      评论:0      收藏:0      [点我收藏+]

标签:

2016-06-24

 

1、HelloWorld.java

package com.HelloWorld;

public class HelloWorld {
    public static void main(String[] args)
    {
        System.out.println("Hello World!");
    }

}

技术分享

2、变量

package com.Test;

public class Test {
    public static void main(String[] args)
    {
        System.out.println("Define a variable a is ");
        int a; //声明变量a
        a = 5;
        
        System.out.println(a); //打印一个整数a
    }

}

技术分享

3、运算符

package com.Test;

public class Operator {
    public static void main(String[] args)
    {
        int a,b,c,d;
        a = 6 + 7;
        System.out.println("a = " +a);
        b = a % 5;
        System.out.println("b = " +b);
        c = b++;
        System.out.println("b++后 b = "+b);
        System.out.println("c = "+c);
        d = ++b;
        System.out.println("++b后 b = "+b);
        System.out.println("d = "+d);
    }

}

技术分享

4、比较运算符

package com.Test;

public class Compare {
    public static void main(String[] args)
    {
        int a = 1;
        double b = 7.2;
        String str1 = "hello";
        String str2 = "CenLiang";
        System.out.println("a等于b: "+(a == b));
        System.out.println("a大于b: "+(a > b));
        System.out.println("a小于等于b: " + (a <= b));
        System.out.println("str1等于str2: "+(str1 == str2));
    }

}

技术分享

5、逻辑运算符

package com.Test;

public class Logic {
    public static void main(String[] args)
    {
        boolean a = true; // a同意
        boolean b = false; // b反对
        boolean c = false; // c反对
        boolean d = true; // d同意
        
        System.out.println(a&&b);
        System.out.println(a||b);
        System.out.println((!a));
        System.out.println((c^d));
    }

}

技术分享

 

java 运算符

标签:

原文地址:http://www.cnblogs.com/cenliang/p/5614851.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!