标签:demo result src dem str 最小 打印 for com
public class TriangleDemo {
public static void main(String[] args) {
for (int j = 1; j <= 5; j++) {
for (int i = 5; i >= j; i--) {
System.out.print(" ");
}
for (int i = 1; i <= j; i++) {
System.out.print("*");
}
for (int i = 1; i < j; i++) {
System.out.print("*");
}
System.out.println();
}
}
}
运行效果:
思路:
依次打印1、2、3部分就行
import java.util.Arrays;
public class Demo1 {
public static void main(String[] args) {
int[] arr = {1, 4, 5, 2, 3};
int[] result = bubbleSort(arr);
System.out.println(Arrays.toString(result));
}
public static int[] bubbleSort(int[] a) {
int temp = 0;
for (int i = 0; i < a.length - 1; i++) {
for (int j = 0; j < a.length - 1 - i; j++) {
if (a[j] > a[j + 1]) {
temp = a[j];
a[j] = a[j+1];
a[j+1] = temp;
}
}
}
return a;
}
}
运行结果:
标签:demo result src dem str 最小 打印 for com
原文地址:https://www.cnblogs.com/happy-lin/p/14952575.html