zoukankan      html  css  js  c++  java
  • Java Tips

    • 1.实现swap:
     1     public static void main(String[] args) {
     2         int []a={1,2};
     3         swap(a);
     4         System.out.println(a[0]);
     5         System.out.println(a[1]);
     6     }
     7     static void swap(int[] a){
     8         int tmp=a[0];
     9         a[0]=a[1];
    10         a[1]=tmp;
    11     }

    •  2.获取行数列数

    二维数组实质是一维数组,一维数组包含子数组就形成了二级!

    1 int i[][] ={{ 1, 2, 8, 9 },
    2       { 2, 4, 8, 12 },
    3       { 4, 7, 10, 13 },
    4       { 6, 8, 11, 15 } };
    5 int rows = i.length;//行数
    6 int columns = i[0].length;//列数

     3.编写cmd脚本执行java程序

    1 cd %cd%
    2 cd bin
    3 cls
    4 java Main
    5 pause

     4.java获取程序执行时间

      以毫秒为单位

    1 long startTime=System.currentTimeMillis();   //获取开始时间
    2  
    3 doSomeThing();  //测试的代码段
    4  
    5 long endTime=System.currentTimeMillis(); //获取结束时间
    6  
    7 System.out.println("程序运行时间: "+(end-start)+"ms");

      以纳秒为单位

    1 long startTime=System.nanoTime();   //获取开始时间
    2  
    3 doSomeThing();  //测试的代码段
    4  
    5 long endTime=System.nanoTime(); //获取结束时间
    6  
    7 System.out.println("程序运行时间: "+(end-start)+"ns");

    5.Java命令行管道输入

    1 cd %cd%
    2 cd bin
    3 cls
    4 echo 5 | java Main
    5 pause
  • 相关阅读:
    windows 物理内存获取
    windbg-.process切换进程(内核)
    cnetos 6.7彻底解决vmware NAT网络问题
    优秀的博客链接地址
    使用Spring MVC统一异常处理实战
    active mq 配置
    socket demo程序
    flume 中的 hdfs sink round 和roll
    软链接与硬链接
    flume A simple example
  • 原文地址:https://www.cnblogs.com/TQCAI/p/7640001.html
Copyright © 2011-2022 走看看