僅供參考http://www.xianlaiwan.cn/article/44178
2018-07-16
public class HelloWorld {//以為簡單,原來都是套路
public static void main(String[] args) {
StringBuilder str=new StringBuilder();
str.append("jaewkjldfxmopzdm");
int l=str.length();
int x=l%3;
for(int i=l/3;i>=0;i--){
str.insert(i*3+x,",");
}
System.out.print(str.toString());
}
}
public static void main(String[] args) {
StringBuilder str=new StringBuilder();
str.append("jaewkjldfxmopzdm");
int l=str.length();
int x=l%3;
for(int i=l/3;i>=0;i--){
str.insert(i*3+x,",");
}
System.out.print(str.toString());
}
}
2018-07-13
字符串型數組把漢字轉換成byte型數組時,只有兩個字節放一起才能說是漢字,單個字節只能說是亂碼,編碼結果也是亂碼,至于出現負數,我想也是編碼導致的把,因為漢字不太可能一半正數,一半負數
2018-07-13
// 定義一個字符串
String s = "aljlkdsflkjsadjfklhasdkjlflkajdflwoiudsafhaasdasd";
// 出現次數
int num = 0;
byte[] b=s.getBytes();
byte[] a="a".getBytes();
byte A=a[0];
for(byte i:b){
if(i==A)
num++;
}
String s = "aljlkdsflkjsadjfklhasdkjlflkajdflwoiudsafhaasdasd";
// 出現次數
int num = 0;
byte[] b=s.getBytes();
byte[] a="a".getBytes();
byte A=a[0];
for(byte i:b){
if(i==A)
num++;
}
2018-07-13
try {
//一些會拋出異常的方法
} catch (Exception e) {
//處理該異常的代碼塊
} finally {
//最終將要執行的代碼塊
}
多重catch的時候,要由小到大,可以理解為作用域大的異常包裹住作用域小的異常,比如:
try{}
catch(InputMismatchException e){}
catch(ArithmeticException e){}
catch(Exception e){}
//一些會拋出異常的方法
} catch (Exception e) {
//處理該異常的代碼塊
} finally {
//最終將要執行的代碼塊
}
多重catch的時候,要由小到大,可以理解為作用域大的異常包裹住作用域小的異常,比如:
try{}
catch(InputMismatchException e){}
catch(ArithmeticException e){}
catch(Exception e){}
2018-07-04