• java程序代码 Exchenge.java


    //Exchange.java

    class Exchange
    {
     public static void main (String args[])
     {
      int num1 = 10, num2 = 20, temp;
      //perform a traditional exchange. this requires the use of a
      //temporary variable. any data types can be exchagned.
      
      System.out.println("Traditional Exchange");
      
      
      temp = num1;
      num1 = num2;
      num2 = temp;
      
      System.out.println("num1 = "+ num1);
      System.out.println("num2 = "+ num2);
      
      //reset variables to original values.
      
      num1 = 10;
      num2 = 20;
      
      //perform an additive exchange. no temporaty variable if needed. only numeric types can be exchanged.
      
      System.out.println("\nAdditive Exchange");
      
      num1 += num2;
      num2 = num1 - num2;
      num1 -=num2;
      
      System.out.println ("num1 = " + num1);
      System.out.println ("num2 = " + num2);
      
      //reset variables to original values.
      
      num1 = 10;
      num2 = 20;
      
      
      //perform a bitwise exclusive ro exchange.no temporary variable is needed. all numeric types except floating-
            // point and double-precision floating-point can be exchanged.
           
            System.out.println("\nBitwise exclusive OR Exchange");
           
           
            num1 ^= num2;
            num2 =num1 ^ num2;
            num1 ^= num2;
           
           
            System.out.println("num1 = " + num1) ;
            System.out.println("num2 = " + num2);  
     }
    }

  • 相关阅读:
    Unable to start adb server: adb server version (32) doesn't match this client (39); killing...
    mysql错误指令:Failed to open file "file_name" error 2/error 22
    爬虫流程概述
    Jupyter Notebook的使用
    markdown语法
    pymysql向表中插入数据
    python创建mysql数据库中的表
    python查询ip地址来源
    Pandas读取csv时设置列名
    程序员面试——位运算
  • 原文地址:https://www.cnblogs.com/josn1984/p/395374.html
Copyright © 2020-2023  润新知