zoukankan      html  css  js  c++  java
  • 程序员的数学基础课 1 append

    数学学霸半年逆袭托福?每天只要两小时,从77分到102分,超简单

    public class Lesson1_append1 {
    	
    	public static void main(String[] args) {
    		//偶数,奇数 count
    		int even_cnt = 0, odd_cnt = 0;
    		//开始,技术时间
    		long start = 0, end = 0;
    		
    		start = System.currentTimeMillis();
    		for (int i = 0; i < 100000000; i++) {
    			//i与1
    			/**
    			 * 请记住“&”是一个按位操作.您可能已经意识到这一点,但根据您提出问题的方式,我并不完全清楚.
    			 * 话虽这么说,理论上的想法是你有一些int,可以通过一些1和0的系列来表示.例如:
    			 *
    			 * ...10110110
    			 * 复制代码
    			 * 在二进制中,因为它是基数2,只要数字的按位版本以0结尾,它就是偶数,当它以1结尾时它是奇数.
    			 *
    			 * 因此,做一个按位&以上为1是:
    			 */
    			if((i & 1) == 0){
    			    even_cnt ++;
    			}else{
    			    odd_cnt ++;
    			}
    			
    		}
    		end = System.currentTimeMillis();
    		System.out.println(end - start);
    		System.out.println(even_cnt + " " + odd_cnt);
    		
    		even_cnt = 0;
    		odd_cnt = 0;
    		start = 0;
    		end = 0;
    		
    		start = System.currentTimeMillis();
    		for (int i = 0; i < 100000000; i++) {
    			/**
    			 * 取余2==0为偶数
    			 */
    			if((i % 2) == 0){
    			    even_cnt ++;
    			}else{
    			    odd_cnt ++;
    			}
    			
    		}
    		end = System.currentTimeMillis();
    		System.out.println(end - start);
    		System.out.println(even_cnt + " " + odd_cnt);
    		
    		
    		start = System.currentTimeMillis();
    		/**
    		 * 交换数字
    		 */
    		for (int i = 0; i < 100000000; i++) {
    			int x = 3, y = 5;
    			x = (x ^ y);
    			y = x ^ y;
    			x = x ^ y;
    		}
    		end = System.currentTimeMillis();
    		System.out.println(end - start);
    		
    		start = System.currentTimeMillis();
    		for (int i = 0; i < 100000000; i++) {
    			int x = 3, y = 5, t = 0;
    			t = y;
    			y = x;
    			x = t;
    		}
    		end = System.currentTimeMillis();
    		System.out.println(end - start);
    		
    //		System.out.println(x + " " + y);
    
    	}
    
    }
    
    
  • 相关阅读:
    js数组操作
    docker操作命令
    swoole使用案例
    swoole实现视频弹幕效果
    swoole的UDP服务
    swoole的TCP服务
    安装回环网卡&安装Linux前准备
    Linux之安装Linux详细步骤
    Spring Boot的面试题
    Shell 脚本面试问题大全
  • 原文地址:https://www.cnblogs.com/ukzq/p/13373982.html
Copyright © 2011-2022 走看看