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

正文內(nèi)容

java編程題全集100題及答案資料(已修改)

2025-07-05 08:34 本頁面
 

【正文】 Java程序設計總復習題編寫一個Java程序在屏幕上輸出“你好!”。(p13,例11) //programme name public class Helloworld { public static void main(String args[]) { (你好! )。 }}2. 編寫一個Java程序,用ifelse語句判斷某年份是否為閏年。// Programme Name public class LeapYear{public static void main(String args[]){int year=2010。 if(!=0) year=(args[0])。if((year%4==0 amp。amp。 year%100!=0)||(year%400==0)) (year+ 年是閏年。)。else (year+ 年不是閏年。)。 } }//ifelse語句編寫一個Java程序在屏幕上輸出1!+2!+3!+……+10!的和。(p64,例22)// programme name public class ForTest { public static void main( String args[] ) { int i,j,mul,sum=0。for(i=1。i=10。i++) {mul=1。for(j=1,j=i。j++) {mul=mul*j。} sum=sum+mul。}(“1!+2!+3!+……+10!= ”+sum)。}}4. (1)編寫一個圓類Circle,該類擁有:①一個成員變量Radius(私有,浮點型); // 存放圓的半徑; ②兩個構(gòu)造方法 Circle( ) // 將半徑設為0 Circle(double r ) //創(chuàng)建Circle對象時將半徑初始化為r ③ 三個成員方法 double getArea( ) //獲取圓的面積 double getPerimeter( ) //獲取圓的周長 void show( ) //將圓的半徑、周長、面積輸出到屏幕(2)編寫一個圓柱體類Cylinder,它繼承于上面的Circle類。還擁有:①一個成員變量double hight(私有,浮點型); // 圓柱體的高; ②構(gòu)造方法 Cylinder (double r, double h ) //創(chuàng)建Circle對象時將半徑初始化為r ③ 成員方法 double getVolume( ) //獲取圓柱體的體積 void showVolume( ) //將圓柱體的體積輸出到屏幕編寫應用程序,創(chuàng)建類的對象,分別設置圓的半徑、圓柱體的高,計算并分別顯示圓半徑、圓面積、圓周長,圓柱體的體積。//Programme Name class Circle { //定義父類園類 private double radius。 //成員變量園半徑 Circle() { //構(gòu)造方法 radius=。 } Circle(double r) { //構(gòu)造方法 radius=r。 } double getPerimeter() { //成員方法求園周長 return 2**radius。 } double getArea() { //成員方法求園面積 return *radius*radius。 } void disp() { //成員方法顯示園半徑、周長、面積 (園半徑=+radius)。 (園周長=+getPerimeter())。 (園面積=+getArea())。 }}class Cylinder extends Circle { //定義子類圓柱類 private double hight。 //成員變量園柱高 Cylinder(double r,double h) { //構(gòu)造方法 super(r)。 hight=h。 } public double getVol() { //成員方法求園柱體積 return getArea()*hight。 } public void dispVol() { //成員方法顯示園柱體積 (圓柱體積=+getVol())。 }}public class TestCylinder { //定義主類public static void main(String[] args) { //主程入口 Circle Ci=new Circle()。 // 生成園類實例 ()。 // 調(diào)用園類的方法 Cylinder Cyl=new Cylinder(,)。 //生成圓柱類實例 ()。 //調(diào)用父類方法 ()。 //調(diào)用子類方法 }}編寫一個Java應用程序,從鍵盤讀取用戶輸入兩個字符串,并重載3個函數(shù)分別實現(xiàn)這兩個字符串的拼接、整數(shù)相加和浮點數(shù)相加。要進行異常處理,對輸入的不符合要求的字符串提示給用戶,不能使程序崩潰。(p39,例210,211)//programme name import .*。public class Strinput { public static void main(String args[]) { String s1,s2,ss,si,sf。 int i1,i2。 float f1,f2。 BufferedReader strin=new BufferedReader(new InputStreamReader())。 try{ (輸入第一個字符串: )。 s1= ()。 (輸入第二個字符串: )。 s2= ()。} catch(Exception e){ (())。} i1 = (s1)。 i2 = (s2)。 f1 = (s1)。 f2 = (s2)。 ss = strAdd(s1,s2)。 si = strAdd(i1,i2)。 sf = strAdd(f1,f2)。 (輸入的二個字符串相加結(jié)果為:+ss )。 (輸入字符串轉(zhuǎn)換為整數(shù)相加結(jié)果為:+si )。 (輸入字符串轉(zhuǎn)換為浮點數(shù)相加結(jié)果為:+sf )。 } String strAdd(String str1,String str2) {return str1+str2。}String strAdd(int int1,int int2) {return (int1+int2)。}String strAdd(float flt1,float flt2) {return (flt1+flt2)。} }6. 應用FileInputStream類,編寫應用程序,從磁盤上讀取一個Java程序,并將源程序代碼顯示在屏幕上。(被讀取的文件路徑為:E:/myjava/)// Programme Name import .*。 public class FISDemo { public static void main(String args[]) { byte[] buf=new byte[2056]。 try{ FileInputStream fileIn=new FileInputStream(e:/myjava/)。 int bytes=(buf,0,2056)。 String str=new String(buf,0,bytes)。 (str)。}catch(Exception e){ ( )。}}編寫一個Java程序?qū)?00,101,102,103,104,,并以相反的順序讀出顯示在屏幕上。(p190,例72) //programme name import .*。 public class IODemo { public static void main( String args[] ) { int data[] = {100,101,102,103,104,105}。int t。try{ DataOutputStream out = new DataOutputStream (new FileOutputStream(“”))。 for(int i=0。i。i++) (data[i])。 ()。 DataInputStream in = new DataInputStream (new FileInputStream(“”))。 for(int i= 。i= 0。i) { t=(data[i])。 (“ ”+t)。 } ( )。 ()。}catch(IOException e){ (())。} }}8. 利用Applet類和Runnable接口實現(xiàn)滾動字幕,其中字幕文字(“學好Java有工作”)和時間間隔(“200”)需要由頁面文件中Applet標記的子標記Param傳遞。import 。import 。import 。public class MoveMessage extends JApplet implements Runnable { String str。 int time。 private Thread thread。 public void init() { setBackground()。 str = getParameter(message)。 String timeArg = getParameter(time)。 time = (timeArg)。 thread = new Thread(this)。 } public void start() { ()。 } public void run() { int x = 0。 Graphics g = getGraphics()。 while (true) { try { (time)。 } catch (Exception e) { ()。 } (0, 0, getWidth(), getHeight())。 (str, x, 30)。 x += 2。 if (x = getWidth()) x = 0。 } }}html body Applet code= width=400 height=60 param name=message value=學好java有工作 param name=time value=200 /Applet /body/html編寫一個Java程序?qū)崿F(xiàn)多線程,在線程中輸出線程的名字,隔300毫秒輸出一次,共輸出20次。(p202,例81) // programme name TestThread。 // 聲明一個子線程類Threaddemo。 class ThreadDemo extends Thread { public ThreadDemo(String str) {super(str)。} public void run() { for(int i=0。i20。i++){(“ ”+())。Try { Sleep(300)。}catch(InterruptedException e){ (())。 Return。}}(“ /end”)。}}public class TestThread { public static void main( String args[] ) { ThreadDemo thread1=new ThreadDemo(“T1”)。 ThreadDemo thread2=new ThreadDemo(“T2”)。 ThreadDemo thread3=new ThreadDemo(“T3”)。 ()。 ()。 ()。 }}10. 編寫程序,在屏幕上顯示帶標題的窗口,并添加一個按鈕。當用戶單擊按鈕時,結(jié)束程序。// Programme Name import .*。import .*。public class ButtonEventDemo extends JPanel implements ActionListener{protected JButton b1。 //聲明一個按鈕對象public ButtonEventDemo() { //構(gòu)造方法ImageIcon ButtonIcon = new ImageIcon(images/)。 //創(chuàng)建按鈕的圖標對象 b1 = new JButton(退出按鈕, ButtonIcon)。 //生成按鈕對象()。 //設置b1的助記符是Alt+E (這是退出按鈕。)。 // 設置按鈕提示條 (b1)。 //往面板對象中加載按鈕 (this)。 //本類對象注冊為按鈕的事件監(jiān)聽器 }public void actionPerformed(ActionEvent e){ //按鈕事件響應方法(0)。 //按b1則退出主程序 } private static void createGUI() { //創(chuàng)建窗體 (true)。 //設置java隱含觀感 JFrame frame = new JFrame(按鈕測試)。 //生成應用程序主窗體 ()。 //設置關閉時隱含操作 ButtonEventDemo CPane = new ButtonEventDemo()。 //生成主類對象面板 (true)。 //面板要求不透明 (CPane)。 //設置主類對象為主窗體的內(nèi)容面板 ()。 //主窗體緊縮顯示 (true)。 //設置主窗體可見 } public static void main(String[] args) { //將createGUI()列入線程 (new Runnable() { public void run() { createGUI()。 } })。 }}11. 利用線程方法編寫JApplet程序,實現(xiàn)在瀏覽器端實時動態(tài)顯示本地系統(tǒng)時鐘// Programme Name import 。import .*。import 。import .*。public class Watch extends Applet { public void paint(Graphics g) { Date d= new Date()。 DateFormat ldf = (, )。 //(現(xiàn)在系統(tǒng)時間是(long):+ (d))。 String time = (d).toString()。 (time, 100, 100)。 try { (1000)。 } catch (InterruptedException e) { } repaint()。 }}htmlheadtitleJavaAppletDemo/title/headbodyapplet code=”” width=300 height=200/applet/body/html // 文件1定義一個表示學生信息的類Student,要求如下:?。?)類Student的成員變量:sNO 表示學號;sName表示姓名;sSex表示性別;sAge表示年齡;sJava:表示Java課程成績。?。?)類Student帶參數(shù)的構(gòu)造方法: 在構(gòu)造方法中通過形參完成對成員變量的賦值操作。(3)類St
點擊復制文檔內(nèi)容
環(huán)評公示相關推薦
文庫吧 www.dybbs8.com
公安備案圖鄂ICP備17016276號-1