zoukankan      html  css  js  c++  java
  • Java中&与&&的区别

    java中&和&&的区别,&和&&虽然都是逻辑运算符,都是判断两边为真,则语句成立,但是在运行的时候,还是有差别的,下面举例来说明。

    一、Java中的&的例子:

    public class Test2{

        public static void main(String[] args){

            int i=3;

            if((i++>5)&(i++<9)){

                System.out.println(i);

                System.out.println("恭喜,执行完了条件语句!");

            }

               System.out.println(i);

        }

    }

     

    从条件判断语句来看,是不成立的,但是i是自加了两次,有初始值3变成5。

    二、Java中&&的例子:

    public class Test2{

        public static void main(String[] args){

            int i=3;

            if((i++>5)&&(i++<9)){

                System.out.println(i);

                System.out.println("恭喜,执行完了条件语句!");

            }    

            System.out.println(i);

        }

    }

    从条件判断语句来看是不成立的,变量i只自加了一次。

  • 相关阅读:
    10-JavaScript 条件语句
    9-JavaScript 比较
    8-JavaScript 运算符
    6-JavaScript 事件
    Sum Problem 重定向文件的使用
    Calculate A + B.
    Vue中computed的本质及与methods的区别
    外部文件使用django的models
    DjangoURL反向解析
    字符串格式化的方式
  • 原文地址:https://www.cnblogs.com/dmfcjd/p/8946314.html
Copyright © 2011-2022 走看看