仅供参考https://www.imooc.com/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