MainActivity如下:
創(chuàng)新互聯(lián)建站于2013年創(chuàng)立,先為中站等服務(wù)建站,中站等地企業(yè),進(jìn)行企業(yè)商務(wù)咨詢服務(wù)。為中站企業(yè)網(wǎng)站制作PC+手機(jī)+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問題。
package cc.test;
import java.util.HashSet;
import java.util.Random;
import android.app.Activity;
import android.os.Bundle;
/**
*
* Demo描述:
* Java中利用Random生成隨機(jī)數(shù)
*
* 參考資料:
* 1
* 2
* 3
* 4
* Thank you very much
*/
public class TestRandomActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
testRandom1();
testRandom2();
testRandom3();
}
//生成隨機(jī)數(shù)
private void testRandom1(){
Random random=new Random();
for (int i = 0; i 5; i++) {
System.out.println("random.nextInt()="+random.nextInt());
}
System.out.println("http://///以上為testRandom1()的測試///////");
}
//在一定范圍內(nèi)生成隨機(jī)數(shù).
//比如此處要求在[0 - n)內(nèi)生成隨機(jī)數(shù).
//注意:包含0不包含n
private void testRandom2(){
Random random=new Random();
for (int i = 0; i 10; i++) {
System.out.println("random.nextInt()="+random.nextInt(20));
}
System.out.println("http://///以上為testRandom2()的測試///////");
}
//在一定范圍內(nèi)生成不重復(fù)的隨機(jī)數(shù)
//在testRandom2中生成的隨機(jī)數(shù)可能會重復(fù).
//在此處避免該問題
private void testRandom3(){
HashSet integerHashSet=new HashSet();
Random random=new Random();
for (int i = 0; i 10; i++) {
int randomInt=random.nextInt(20);
System.out.println("生成的randomInt="+randomInt);
if (!integerHashSet.contains(randomInt)) {
integerHashSet.add(randomInt);
System.out.println("添加進(jìn)HashSet的randomInt="+randomInt);
}else {
System.out.println("該數(shù)字已經(jīng)被添加,不能重復(fù)添加");
}
}
System.out.println("http://///以上為testRandom3()的測試///////");
}
}
main.xml如下:
若使用的是vivo手機(jī),Android系統(tǒng)是多個功能和服務(wù)的集合體,比如權(quán)限管理、藍(lán)牙設(shè)置、電話服務(wù)、指紋與密碼等常用功能有關(guān)的耗電會被計入Android系統(tǒng),如果第三方軟件使用到這些功能,電量也會被計入Android系統(tǒng),所以我們看到Android系統(tǒng)程序耗電較高,實(shí)際和第三方軟件的使用情況有關(guān),您可以使用“一鍵加速”清理后臺不必要的程序,適當(dāng)調(diào)低屏幕亮度和音量;另外進(jìn)入設(shè)置--電池,根據(jù)手機(jī)電量情況選擇合適的省電模式,延長手機(jī)續(xù)航時間。
10和100都是int,所以是0,轉(zhuǎn)化成double就變成0.0了
要這樣1f/100
byte[] buffer = new byte[100];
int c = -1;
InputStream is = .....這些都是你自己實(shí)現(xiàn)的
OutputStream os = .....
while ((c = is.read(buffer, 0, buffer.len)) != -1) {
os.write(buffer, 0, c);//c長度不夠后面會自動不上空格,因?yàn)閎uffer的長度是100
}
分享題目:android100,appandroid100 zhengfuz
網(wǎng)站鏈接:http://sd-ha.com/article22/dseshjc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供響應(yīng)式網(wǎng)站、標(biāo)簽優(yōu)化、做網(wǎng)站、Google、動態(tài)網(wǎng)站、服務(wù)器托管
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)