zoukankan      html  css  js  c++  java
  • java 第3章 运算符

    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));
        }
    
    }

  • 相关阅读:
    C#计算代码的执行耗时
    c#值类型和引用类型
    C#类、接口、虚方法和抽象方法
    15,了解如何在闭包里使用外围作用域中的变量
    函数闭包,golbal,nonlocal
    init())函数和main()函数
    函数的命名空间
    函数的默认参数是可变不可变引起的奇怪返回值
    遍历目录
    super顺序
  • 原文地址:https://www.cnblogs.com/cenliang/p/5614851.html
Copyright © 2011-2022 走看看