public class test{
public static void main(String[] args){
method();
}
//給定一個(gè)整數(shù)n,n為數(shù)組arr的長(zhǎng)度,在給定一個(gè)整數(shù)k,求出arr中隨機(jī)三個(gè)數(shù)之和小于
//k值的三元數(shù)組個(gè)數(shù)
public static void method(){
System.out.println("輸入一個(gè)正數(shù)n");
? ? ? ? Scanner sc=new Scanner(System.in);
? ? ? ? Random r=new Random();
? ? ? ? int n=sc.nextInt();
? ? ? ? int[] arr=new int[n];
? ? ? ? for(int i=0;i<n;i++){
? ? ? ? ? ? arr[i]=(int) (Math.random()*n);
? ? ? ? }
? ? ? ? for(int m:arr){
? ? ? ? ? ? System.out.print(m+" ");
? ? ? ? }
? ? ? ? System.out.println();
? ? ? ? System.out.println("輸入一個(gè)正數(shù)k");
? ? ? ? int k=sc.nextInt();
? ? ? ? int m=0;
? ? ? ? for(int i=0;i<arr.length;i++){
? ? ? ? ? ? for(int j=0;j<arr.length;j++){
? ? ? ? ? ? ? ? for(int h=0;h<arr.length;h++){
? ? ? ? ? ? ? ? ? ? if(i!=j&&j!=h&&h!=i&&(arr[i]+arr[j]+arr[h])<k){
? ? ? ? ? ? ? ? ? ? ? ? m++;
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? System.out.println(m+"組滿足條件的三元組");
}
}