zoukankan      html  css  js  c++  java
  • 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);  
     }
    }

  • 相关阅读:
    eclipse中不能识别enum
    The source attachment does not contain the source for the file Activity.class
    ASP.NET应用程序脱机问题
    鱼仔系统部署教程
    鱼仔系统开发教程
    mysql innodb cluster 无感知集群
    Mysql 8.0 新特性测试
    随笔1
    音频输出格式
    2012.02.03(S3C6410中文手册笔记)(一)
  • 原文地址:https://www.cnblogs.com/josn1984/p/395374.html
Copyright © 2011-2022 走看看