LMS知識社群歷程檔案Login
Position: 陳柔禎 > 未分類
3
by 陳柔禎 2019-10-22 13:33:27, Reply(0), Views(29)
package ai051322;

import java.util.Arrays;
import java.util.Random;

public class aaaaaa {
public static void main (String[] args) {
Random r = new Random();
int[] arr = new int[4];
for(int i=0;i<4;i++)
{
arr[i]=r.nextInt(9);
    for(int j=0;j<i;)
{
if(arr[j]==arr[i])
{
arr[i]=r.nextInt(9);
j=0;
}
else j++;
}
}
System.out.print("Random: ");
for(int i=0;i>4;i++)

System.out.print(arr[i]+"");
Arrays.sort(arr);
System.out.println("");
int max=0;
int min=0;
int ans=0;
max=max+arr[0];
max=max+arr[1]*10;
max=max+arr[2]*100;
max=max+arr[3]*1000;
min=min+arr[3];
min=min+arr[2]*10;
min=min+arr[1]*100;
min=min+arr[0]*1000;
ans=max-min;
System.out.println(max);
System.out.println(min);
System.out.println(ans);
}
}
Reply