亂數取不重複6 個數· GitHub

文章推薦指數: 80 %
投票人數:10人

亂數取不重複6 個數========== */. public class Random_01 {. public static void main(String[] args) {. Random r = new Random();. int[] sixNum = new int[6];. Skiptocontent Allgists BacktoGitHub Signin Signup Sign in Sign up {{message}} Instantlysharecode,notes,andsnippets. HabaCo/1030528_Ex1.java LastactiveSep7,2020 Star 3 Fork 0 Star Code Revisions 7 Stars 3 Embed Whatwouldyouliketodo? Embed Embedthisgistinyourwebsite. Share Copysharablelinkforthisgist. Clonevia HTTPS ClonewithGitorcheckoutwithSVNusingtherepository’swebaddress. LearnmoreaboutcloneURLs DownloadZIP 亂數取不重複6個數 Raw 1030528_Ex1.java ThisfilecontainsbidirectionalUnicodetextthatmaybeinterpretedorcompileddifferentlythanwhatappearsbelow.Toreview,openthefileinaneditorthatrevealshiddenUnicodecharacters. LearnmoreaboutbidirectionalUnicodecharacters Showhiddencharacters importjava.util.Arrays; importjava.util.Random; /*==========亂數取不重複6個數==========*/ publicclassRandom_01{ publicstaticvoidmain(String[]args){ Randomr=newRandom(); int[]sixNum=newint[6]; /**-------------------------------------------------- eg. 步驟for(i=0ton)ar[i]=rand() Step1 i=0->ar[0]=9 Step2 i=1->ar[1]=1 與前一個i[0]比較 Step3 i=2->ar[2]=9 與前兩個i[0]、i[1]比較 再取亂數->i[2]=3 . . 需要1.for(i=0ton)給予arr[i]隨機數 2.for(j=0toi)與arr[i]之前的數列比較是否相同 -----------------------------------------------------*/ for(inti=0;i<6;i++){ sixNum[i]=r.nextInt(6)+1; //將隨機數(1-49)放入sixNum[i] for(intj=0;jsixNum[j]){ // intt=sixNum[i]; // sixNum[i]=sixNum[j]; // sixNum[j]=t; // } System.out.println(); System.out.print("sort:"); for(inti=0;i<6;i++) System.out.print(sixNum[i]+""); } } Signupforfree tojointhisconversationonGitHub. Alreadyhaveanaccount? Signintocomment Youcan’tperformthatactionatthistime. Yousignedinwithanothertaborwindow.Reloadtorefreshyoursession. Yousignedoutinanothertaborwindow.Reloadtorefreshyoursession.



請為這篇文章評分?