JAVA算法学习过程

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小时制。
此思路和代码其实是仿照尚硅谷的教程,自己进行总结,巩固学习。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值