資源描述:
《【java經典算法】有一個已經排好序的數組?,F輸入一個數,要求按原來的規(guī)律將它插入數組中》由會員上傳分享,免費在線閱讀,更多相關內容在行業(yè)資料-天天文庫。
1、//Java里彈對話框importjavax.swing.JOptionPane;importjava.util.Arrays;importjava.util.Random;publicclassArraySortMine{publicstaticvoidmain(String[]args){inttemp=0;intmyarr[]=newint[12];Randomr=newRandom();for(inti=1;i<=10;i++)myarr[i]=r.nextInt(100);System.out.println("Theorignaldata:");for(intk=1;k<=10
2、;k++)System.out.print(myarr[k]+",");for(inti=1;i<=9;i++)for(intk=i+1;k<=10;k++)if(myarr[i]>myarr[k]){temp=myarr[i];myarr[i]=myarr[k];myarr[k]=temp;}System.out.println();System.out.println("Thesortdata:");for(intk=1;k<=10;k++)System.out.print(myarr[k]+",");//herewillaDiamonds//我想讓對話框出現提示三次(這時是alert
3、),,之前的提示應該有兩個按鈕,Yes和No用戶體驗思想,不多說//http://blog.sina.com.cn/robertlizhiqiangObject[]possibleValues={"insertdatabymysesf","PleaseFilldataforme!"};ObjectselectedValue=JOptionPane.showInputDialog(null,"Chooseone","Input",JOptionPane.INFORMATION_MESSAGE,null,possibleValues,possibleValues[0]);if(selected
4、Value=="insertdatabymysesf"){StringinputValue=JOptionPane.showInputDialog("Pleaseinputyouraccessdata(Only3times)!");//firsttimeinputdataif(inputValue!=null&&!inputValue.equals("")){try{myarr[11]=Integer.parseInt(inputValue);}catch(NumberFormatExceptione){//System.out.println(e.getMessage());/**JOp
5、tionPane.showMessageDialog(null,"yourdata:"+*e.getMessage()+*"isnotNumber!Systemwillselectoneforyou!",*"alert",JOptionPane.ERROR_MESSAGE);myarr[11]=*r.nextInt(100);*///secondtimetoinputdataObject[]options={"讓我再輸一次吧","請系統(tǒng)自動為我輸入"};booleanoptionYes=false;optionYes=JOptionPane.showOptionDialog(null,"你
6、妹啊,你輸的"+e.getMessage()+"就不是數字!","你故意的搞我程序的吧",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE,null,options,options[0])==JOptionPane.YES_OPTION;if(optionYes){//繼續(xù)代碼StringinputValue2=JOptionPane.showInputDialog("Pleaseinputyouraccessdata(NowLasttimes)!");if(inputValue2!=null&&!inputValue2.equa
7、ls("")){try{myarr[11]=Integer.parseInt(inputValue2);}catch(NumberFormatExceptione1){//Thelasttimetopermittoinputdata!Object[]optionsThird={"給我最后次機會吧","系統(tǒng)給我輸吧"};booleanoptionYesThird=false;optionYesThird=JOptionPa