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

  • 相关阅读:
    解题报告:POJ1852 Ants
    解题报告:POJ2573 Bridge(分析建模)
    POJ 3321 Apple Tree(树状数组模板)
    PAT1139 First Contact
    POJ3259 SPFA判定负环
    HDOJ2586 最近公共祖先模板
    树的直径与最近公共祖先
    字符数组_随机存储
    青鸟资料下载
    软件测试(4)_LoadRunner使用
  • 原文地址:https://www.cnblogs.com/josn1984/p/395374.html
Copyright © 2011-2022 走看看