您的位置:首页 > 编程语言 > Java开发

java web week_one

2017-05-19 23:18 351 查看

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());
}
}
}
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: