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());
}
}
}
}
}
}