java web week_one

本文提供了三个Java编程示例:打印九九乘法表、求整数数组中的最大值以及读取目录下所有MP3音乐文件的路径。

1.在控制台打印出九九乘法表

public class Jiujiu {
public static void main(String[] args) {
for (int i = 1; i < 10; i++) {
for (int j = 1; j <= i; j++) {
System.out.print(i + " x " + j + " = " + i * j + "\t");
if (i == j) {
System.out.println();
}
}
}
}
}

2.写一个函数用于求出整数数组中的最大值

public class MaxNumber {
public static void main(String[] args) {
Random random = new Random();    
int[] array = new int[10];
    for (int i = 0; i < 10; i++) {
        int num = random.nextInt(10) + 1;//[1,10)之前的数
        array[i] = num;
    }

    int i;
    for (i = 0; i < array.length; i++) {
        System.out.print(array[i] + " ");
    }

    if (i == array.length){
        System.out.println();
    }

    System.out.println(forMax(array));
}

private static int forMax(int[] array) {
    int max = array[0];
    for (int i = 0; i < array.length; i++) {
        if (max <= array[i]){
            max = array[i];
        }
    }

    return max;
}
}


4.音乐文件读取工具

public class Music {
public static void main(String[] args) {
File file = new File("musics");
findMP3(file, file.getAbsolutePath());
}
private static void findMP3(File songFile, String songPath) {
    File[] songList = songFile.listFiles();

    if (songList != null) {
        for (File s : songList) {
            if (s.isDirectory()) {
                findMP3(s, s.getAbsolutePath());
            } else {
                if (s.getAbsolutePath().endsWith(".mp3")
                        || s.getAbsolutePath().endsWith("MP3")) {
                    System.out.println(s.getAbsolutePath());
                }
            }
        }
    }
}
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值