第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

為什么用for(int i =0;i<=(int)(Math.random()*10);i++)方法來獲取字符串的長度最多只能9位,提前變量賦值隨機(jī)數(shù)卻可以得到10位

public?void?testsort3(){
		char[]?string=?{'0','1','2','3','4','5','6',
			?????'7','8','9','a','b','c','d',
			???	??'e','f','g','h','i','j','k',				????????
			???	??'l','m','n','o','p','q','r',				????????
			???	??'s','t','u','v','w','x','y',				????????
			???	??'z','A','B','C','D','E','F',				????????
			???	??'G','H','I','J','K','L','M',				????????
			???	??'N','O','P','Q','R','S','T',				????????
			???	??'U','V','W','X','Y','Z'};		
	List<String>?stringList?=?new?ArrayList();		
	//可變字符串		
	StringBuilder?sb??;		
	//隨機(jī)字符的下標(biāo)		
	int?random?;		
	//循環(huán)添加字符的次數(shù)		
	int?cishu;		
	//隨機(jī)字符串		
	String?s1;		
	do{			
	????sb?=?new?StringBuilder();			
	????cishu?=?(int)(Math.random()*10);			
	????//for(int?i?=0;i<=(int)(Math.random()*10);i++){			
	????for(int?i?=0;i<=cishu;i++){				
	????????random?=(int)?((Math.random()*62));							
	????????sb.append(string[random]);					
	?????}			
	?????s1?=?sb.toString();			
	?????if(!stringList.contains(s1)){				
	?????????stringList.add(s1);								
	?????????System.out.println("添加隨機(jī)字符串:"+s1+"---長度為:"+s1.length());			
	?????????}		}while(stringList.size()<10);
	?????????//排序前		
	?????????System.out.println(stringList.toString());		
	?????????Collections.sort(stringList);
	?????????//排序后		
	?????????System.out.println(stringList.toString());			}


正在回答

3 回答

提前賦值隨機(jī)數(shù)其實(shí)是一種方法的重載,它表示取指定范圍的數(shù)。例如: Random r = new Random(),? int a = r.nextInt(100)表示可以取0-100的任意整數(shù)。而int b = r.nextInt() * 100取不到100,只能取0-99中的任意整數(shù)

0 回復(fù) 有任何疑惑可以回復(fù)我~
#1

慕絲1322028

“提前賦值隨機(jī)數(shù)”改為“提前變量賦值隨機(jī)數(shù)卻可以得到10位”,當(dāng)時(shí)復(fù)制過來時(shí)弄錯(cuò)了
2020-03-23 回復(fù) 有任何疑惑可以回復(fù)我~

我是好奇干嘛在for循環(huán)中放一個(gè)會(huì)變的數(shù)

0 回復(fù) 有任何疑惑可以回復(fù)我~

具體代碼在22-24行,23行注釋掉的代碼為什么不行,一定要提前產(chǎn)生隨機(jī)數(shù)cishu

0 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消

為什么用for(int i =0;i<=(int)(Math.random()*10);i++)方法來獲取字符串的長度最多只能9位,提前變量賦值隨機(jī)數(shù)卻可以得到10位

我要回答 關(guān)注問題
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)