1.
codePointCount()就是准确计算unicode字符的数量,而不是char的数量
2.
StringBuilder sb=new StringBuilder();
sb.append(“hh”);
sb.append(32);
sb显示hh32
3.
输入
Scanner s=new Scanner(System.in);
String a=s.nextLine();//输入字符串
4.
double d = 12345.67890;
System.out.printf(“%8.3f”, d);//8个字符宽度,小数点后3位的浮点数
显示12345.679
5.
String name=”you”;
String s=String.format(“fuck %s”,name)
6.
PrintWriter out = new PrintWriter(“1.txt”, “UTF-8”);
写入文件,如果没有则创建文件
Scanner in=new Scanner(Paths.get(“1.txt”), “UTF-8”);
读取文件
7.
if( )
{ }
else if()
{}
else
{}
else子句与最近邻的if构成一组
8.
while()
{}
do
{}
while()
9.
for(int i=1;i<9;i++)
{}
i不能再循环之外使用,除非在循环外声明
int i;
for(i=1;i<9;i++)
{}
10.
switch()
{
case 1:
······
break;
case 2:
······
break;
default:
······
break;
}
11.
带标签的break语句,跳出多重循环嵌套语句
label1:
while()
{
while()
{
break label1;
}
}
12.
存储同一类型值的集合
[]表示数组
int[] a=new int[100];
13.
初始化 数组(不是普通变量,依然有new)
数字 0
char 方框
boolen false
对象数组元素 null
14.
for(int element:collection)
{}
遍历collection中每一个element
15.
数组初始化
int[] a={1,2,3};
或
a=new int[] {4,5,6};
16.
数组用 = 复制的引用
Arrays.copyOf 复制的拷贝
int[] a={4,5,6};
int[] b= Arrays.copyOf(a,a.length);
a[1]=9;
System.out.println(b[1]);
显示b为5,若用=则为9
17.
class Main中
public static void main(String[] args)
运行时在命令行中用
java Main -g world
args[0]为-g
args[1]为world
18.
排序
Arrays.sort(a);
19.
二维数组
int[][]
不能用for(int element:collection)循环
必须用2层