java编程中容易犯2的细节汇总

1.for() 和 while() 执行步骤

     for(s1;s2;s3){ s4;}

     1.进入循环执行s1; 
     2.执行s2;//条件为真才执行s4,不然就跳出for了.
     3,执行s4;
     4,执行s3;
     5,再回到第2步开始执行

     

  int i=0;
  while( i++<10){
  System.out.print(i+"  ");//1  2  3  4  5  6  7  8  9  10  
  }
  int i=0;
  while( ++i<10){
  System.out.print(i+"  ");//1  2  3  4  5  6  7  8  9    
  }

2.char--->int的转换

  char a='9';
  int t=2+a;//59
  int  b=(int)a;//57
  int c=Integer.parseInt(a+"");//9

3.二进制---->十进制

 String s="1010";
 BigInteger bi=new BigInteger(s, 2); 
 System.out.println(bi.toString(10));//10
4.String的拼接+的注意事项
String s0=null; 
String s1="";
String s2="ab";
String s3=s0+s2;// nullab
String s4=s1+s2;// ab



ps:持续更新....

     

原文地址:https://www.cnblogs.com/oversea201405/p/3766894.html