等腰三角形的代码及各类代码
import java.util.Scanner;
public class Dy {
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
System.out.println("请输入行数:");
int longer=input.nextInt();
for(int i=0;i<=longer;i++){
for(int j=longer-i-1;j>=0;j--){
System.out.print(" ");
}
for(int j=1;j<=2*i-1;j++){
System.out.print("*");
}
System.out.println();
}
}
}
插入类
import java.util.*;
public class Dy {
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
int [] old=new int[]{10,56,24,60};
Arrays.sort(old);
int [] news=new int[old.length+1];
for(int i=0;i<old.length;i++){
news[i]=old[i];
}
System.out.println("请输入插入数字:");
int score=input.nextInt();
int index=news.length-1;
for(int i=0;i<news.length;i++){
if(news[i]>score){
index=i;
break;
}
}
for(int i=news.length-1;i>index;i--){
news[i]=news[i-1];
}
news[index]=score;
for(int i=0;i<news.length;i++){
System.out.println(news[i]);
}
}
}
排序(冒泡)
public class Test12 {
public static void main(String[] args) {
int [] news=new int[]{20,61,84,74,0,30};
for(int i=0;i<news.length;i++){
for(int j=0;j<news.length-i-1;j++){
if(news[j]>news[j+1]){
int temp=news[j];
news[j]=news[j+1];
news[j+1]=temp;
}
}
}
for(int i=0;i<news.length;i++){
System.out.println(news[i]);
}
}
}