freepeople性欧美熟妇, 色戒完整版无删减158分钟hd, 无码精品国产vα在线观看DVD, 丰满少妇伦精品无码专区在线观看,艾栗栗与纹身男宾馆3p50分钟,国产AV片在线观看,黑人与美女高潮,18岁女RAPPERDISSSUBS,国产手机在机看影片

正文內(nèi)容

java程序設(shè)計(jì)-習(xí)題參考答案(參考版)

2025-07-01 08:32本頁(yè)面
  

【正文】 }}13.編寫一個(gè)線程同步的程序:有一個(gè)字符緩沖區(qū),長(zhǎng)度為length,我們創(chuàng)建兩個(gè)線程,其中一個(gè)線程向字符緩沖區(qū)寫入一個(gè)字符,(字符緩沖區(qū)一次只能裝入一。 }catch(InterruptedException e) {} () 。 () 。 Thread2 t2 = new Thread2()。 (100)。 i=10 。 (100)。b39。 i8 。)。 i++) { (39。解:class Thread1 extends Thread{ public void run() { for(int i=0 。 ()。 Thread t2 = new Thread (o)。 Output o = new Output(rt)。 }catch(InterruptedException e){} } }}public class Hello { public static void main(String args[]){ Result rt = new Result()。 (temp)。i200。 } public void run(){ long temp。 }catch(InterruptedException e){} } }}class Output implements Runnable{ Result rt。 (tmp)。i++){ long tmp=0。 } public void run(){ for(int i=2。 }}class Addition implements Runnable{ Result rt。 public void write(long t){ total=total+t。 }}答:輸出結(jié)果為:thread is daemon01234main done!11.編寫程序?qū)崿F(xiàn)如下功能:一個(gè)線程進(jìn)行如下運(yùn)算1*2+2*3+3*4+……+1999*2000,而另一個(gè)線程則每隔一段時(shí)間讀取前一個(gè)線程的運(yùn)算結(jié)果。 try { (900)。 (true)。 } }catch (InterruptedException e){} (thread done!)。i++){ (i)。 try { for(int i=0。10.下列程序輸出的結(jié)果是什么?class Daemon extends Thread { public void run() { if(()==false) (thread is not daemon)。當(dāng)一個(gè)優(yōu)先級(jí)低的線程運(yùn)行過(guò)程中,來(lái)了一個(gè)高優(yōu)先級(jí)線程,在時(shí)間片方式下,優(yōu)先級(jí)高的線程要等優(yōu)先級(jí)低的線程時(shí)間片運(yùn)行完畢才能被調(diào)度,而在搶占式調(diào)度方式下,優(yōu)先級(jí)高的線程可以立刻獲得CPU的控制權(quán)。以下三種Thread類的構(gòu)造方法實(shí)現(xiàn)線程創(chuàng)建的同時(shí)指定其屬于哪個(gè)線程組。在線程創(chuàng)建時(shí),可以將線程放在某個(gè)指定的線程組中,也可以將它放在一個(gè)默認(rèn)的線程組。6.wait()方法和sleep()方法的區(qū)別是什么?答:sleep()方法使線程進(jìn)入睡眠狀態(tài),但它并不會(huì)釋放線程持有的資源,不能被其他資源喚醒,不過(guò)睡眠一段時(shí)間會(huì)自動(dòng)醒過(guò)來(lái),而wait()方法讓線程進(jìn)入等待狀態(tài)的同時(shí)也釋放了持有的資源,能被其他資源喚醒。 ()。 Thread t2 = new Thread (o)。 Output o = new Output(s)。 }catch(InterruptedException e){} } }}public class Hello { public static void main(String args[]){ Stack s = new Stack()。 (向Stack取出數(shù)字:+temp)。i5。 } public void run(){ int temp。 }catch(InterruptedException e){} } }}class Output implements Runnable{ Stack sstack。 (向Stack放入數(shù)字:+i)。i5。 public Input(Stack s){ sstack=s。 ()。 } } public int get(){ synchronized (this){ while(len ==0){ try{ ()。 len=1。 public void put(int t){ synchronized (this){ while(len == 1){ try{ ()。 }}方法二(對(duì)象同步):class Stack{ private int number。 ()。 } public synchronized int get(){ while(len ==0){ try{ ()。 len=1。 public synchronized void put(int t){ while(len == 1){ try{ ()。方法一(方法同步):class Stack{ private int number。     } catch (InterruptedException e) {}   }  }}3.什么是線程的生命期?它包括哪幾種狀態(tài)?它們的關(guān)系是什么?答:線程的生命期是指從線程被創(chuàng)建開始到死亡的過(guò)程,通常包括5種狀態(tài):新建、就緒、運(yùn)行、阻塞、死亡。 i++) {    (getName()+被調(diào)用!)。}  public void run() {    for (int i = 0?!                ry {      sleep(10)。 i 10。   public SimpleThread(String str) {    threadname=str。答:兩種途徑來(lái)實(shí)現(xiàn)多線程的創(chuàng)建:一種是直接繼承Thread類并重寫其中的run( ) 方法 ,另一種是使用Runnable接口。Java的多線程就是系統(tǒng)每次給Java程序一個(gè)CPU時(shí)間,Java虛擬處理機(jī)在多個(gè)線程之間輪流切換,保證每個(gè)線程都能機(jī)會(huì)使用CPU資源,不過(guò)每個(gè)時(shí)刻只能有一個(gè)線程在執(zhí)行。它是比進(jìn)程更小的能獨(dú)立運(yùn)行的基本單位。每一個(gè)進(jìn)程都有自己的一塊內(nèi)存空間和一組系統(tǒng)資源,它們之間都是獨(dú)立的。所謂線程是指進(jìn)程中單一順序的執(zhí)行流。i++) (b[i])。 for(int i=0。 else (字符串1是字符串2的子串)。 String str2 = ()。 String str1 = ()。public class Hello { public static void main(String[] args) { Scanner scan = new Scanner()。解:import 。(2)檢驗(yàn)第一個(gè)串是否為第二個(gè)串的子串。 (total/)。 if(max (args[i])) max=(args[i])。i。 int max=0。 } }}解:輸出的結(jié)果是: FridaySaturdaySundayMonday,Tuesday7.編寫程序,在命令行輸入java 類文件名11 24 62 73 103 56,求這一串?dāng)?shù)字的最大值和平均數(shù)。 \\)。Saturday\\Sunday Monday,Tuesday。6.下列程序輸出的結(jié)果是什么?import .*。public boolean hasMoreTokens()。public String nextToken(String delim)功能:以delim作為分隔符逐個(gè)獲取字符串中的單詞并返回該字符串。常用的方法有如下幾種:public String nextToken()。 String s5= s1s2。答:語(yǔ)句或表達(dá)式不正確的有: s3=Hello World! 。y39。s1=s2char c=(())。StringBuffer s6=s3+s4。s3=Hello World! 。 (sb2為:+s2)。 (s2為:+s2)。 sb2=(2,4)。 StringBuffer sb2。 StringBuffer sb1=new StringBuffer (It is Java)。 s4=s2。 String s2=new String(Hello World! )。 }}第7章1.String類型與StringBuffer類型的區(qū)別是什么?答:String類型的字符串是對(duì)原字符串的拷貝進(jìn)行操作,而StringBuffer類型的字符串是對(duì)原字符串本身進(jìn)行操作的,操作后的結(jié)果會(huì)使原字符串發(fā)生改變。 height = h。 }}class Rectangle extends Shape{ public float width,height。 Circle(float r) { = r。abstract class Shape{ abstract float area()。方法:抽象出一個(gè)共享父類,定義一函數(shù)為求面積的公共界面,再重新定義各形狀的求面積函數(shù)。在主類中創(chuàng)建不同類的對(duì)象,并求得不同形狀的面積。14.利用多態(tài)性編程,實(shí)現(xiàn)求三角形、正方形和圓形面積。多態(tài)性又被稱為“一個(gè)名字,多個(gè)方法”。即為同一個(gè)方法定義幾個(gè)版本,運(yùn)行時(shí)根據(jù)不同情況執(zhí)行不同的版本。由于父類代表了所有子類的共性,而子類既可繼承其父類的共性,又可以具有本身獨(dú)特的個(gè)性,在定義子類時(shí),只要定義它本身所特有的屬性與方法就可以了。12.什么是繼承?繼承的意義?如何定義繼承關(guān)系?答:繼承是一種由已有的類創(chuàng)建新類的機(jī)制。 }}11.解釋this和super的意義和作用。 (b)。 ()。 Complex b=new Complex(3,4)。 } public void tostring(){ (real+++imagin+i)。 imagin=imagin*。 return this。 } public Complex plexMinus(Complex Number){ real=。 imagin=imagin+。 } public double getImagin(){ return imagin。 imagin=i。 imagin=0。 private double imagin。 (1)復(fù)數(shù)類Complex的屬性: real代表復(fù)數(shù)的實(shí)數(shù)部分 imagin代表復(fù)數(shù)的虛數(shù)部分(2) 復(fù)數(shù)類Complex的方法: Complex( ):構(gòu)造函數(shù),將實(shí)部、虛部都置為0;Complex(double r,double i ):構(gòu)造函數(shù),創(chuàng)建復(fù)數(shù)對(duì)象的同時(shí)完成復(fù)數(shù)的實(shí)部、虛部的初始化,r為實(shí)部的初值,i為虛部的初值; getReal( ):獲得復(fù)數(shù)對(duì)象的實(shí)部; getImagin( ):獲得復(fù)數(shù)對(duì)象的虛部;plexAdd(Complex Number):當(dāng)前復(fù)數(shù)對(duì)象與形參復(fù)數(shù)對(duì)象相加,所得的結(jié)果也是復(fù)數(shù)值,返回給此方法的調(diào)用者;plexMinus(Complex Number):當(dāng)前復(fù)數(shù)對(duì)象與形參復(fù)數(shù)對(duì)象相減,所得的結(jié)果也是復(fù)數(shù)值,返回給此方法的調(diào)用者;plexMulti(Complex Number):當(dāng)前復(fù)數(shù)對(duì)象與形參復(fù)數(shù)對(duì)象相乘,所得的結(jié)果也是復(fù)數(shù)值,返回給此方法的調(diào)用者;toString( ):把當(dāng)前復(fù)數(shù)對(duì)象的實(shí)部、虛部組合成a+bi的字符串形式,其中a和b分別為實(shí)部和虛部的數(shù)據(jù)。 ()。 ()。 ()。 } public static void main(String args[]){ student Lee=new student(2007070130,Li Ming,M,18)。 } void show_old(){ (the student old is:+old)。 } void show_name(){ (the student name is:+name)。 =old。 =name。 private int old。 private String name。書寫Java程序創(chuàng)建student類的對(duì)象及測(cè)試其方法的功能。(D)public void bb( ){(hello)。(B)int y=0。 (\nx=++ y=+)。 ,:\mydi
點(diǎn)擊復(fù)制文檔內(nèi)容
物理相關(guān)推薦
文庫(kù)吧 www.dybbs8.com
備案圖鄂ICP備17016276號(hào)-1