99 乘法表倒立
public class MultTable { public static void main(String args[]) { for(int i=1;i<=9;i++) { for(int j=i;j<=9;j++) { System.out.print(i+"*"+j+"="+i*j+" "); } System.out.println(); } } }
猜数
import java.util.Scanner; import java.util.Random; public class CaiSu { public static void main(String []args) { Scanner sc= new Scanner(System.in); Random rd1=new Random(); int rd= rd1.nextInt(10)+1; String flag="y"; do{ System.out.println("请输入一个数"); int a=sc.nextInt(); if(rd==a) { System.out.println("你太聪明了。这样也能猜对。。"); } if(rd>a) { System.out.println("你输入的数太小了"); } if(rd<a) { System.out.println("你输入的数太大了"); } System.out.println("是否还要继续"); flag=sc.next(); }while("y".equals(flag)||"Y".equals(flag)); } }
插入排序
public class InjectionSort { public static void injectionSort(int[] number){ for(int j = 1;j<number.length;j++){ int tmp = number[j]; int i = j-1; while(tmp<number[i]){ number[i+1] = number[i]; i–; if(i == -1) break; } number[i+1] = tmp; } } public static void main(String[] args){ int[] num = {5,46,26,67,2,35}; injectionSort(num); for(int i = 0;i<num.length;i++) { System.out.println(num[i]); } } }