import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
public class first {
public static void main(String[] args) {
int a[] = {2,7,5,1,4};
int[] b = new int[100000];
for(int i = 0; i < 100000; i++) {
b[i] = (int) (Math.random() * 1000);
}
Date date1 = new Date();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String format1 = simpleDateFormat.format(date1);
System.out.println(format1);
Bsort(b);
Date date11 = new Date();
String format11 = simpleDateFormat.format(date11);
System.out.println(format11);
}
public static void Bsort(int[] a) {
int c;
for(int i = 0 ; i < a.length-1; i++) {
for(int j = 0; j < a.length-1; j++) {
if(a[j] > a[j+1]) {
c = a[j];
a[j] = a[j+1];
a[j+1] = c;
}
}
}
}
public void show(int[] a) {
for(int i=0;i<a.length;i++) {
System.out.print(a[i] + " ");
}
}
}
记录一下 由于基础不扎实而遇到的坑。
一:在首次进行初始化数组时,直接使用的时int[] b = null。 当给定b为空指针(引用)之后无法进行数组内成员赋值,此时测试的一种方法可以使其指针直接引用其他同类型的地址。
二:在对测试数组进行随机数赋值时,开始写的时b[i] = (int) Math.random() * 100; 这里的错误在于(int) 强制转换只针对了Math.randowm(),而其随机函数给出的时一个dounle的(0-1)。
三:时间表达格式中的大小写都是有意义的,就像时间中小时HH表示24小时制而hh则表示12小时制。
此思路和代码其实是仿照尚硅谷的教程,自己进行总结,巩固学习。