




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、2.1從輸入對話框讀入double型的華氏度,將其轉(zhuǎn)換為攝氏度,并在消息對話框中顯示結(jié)果。Celsius = (5/9)*(Fahrenheit-32)import javax.swing.JOptionPane;public class Exercise2_1 public static void main(String args) String fahrenheitString = JOptionPane.showInputDialog(null, Enter a temperature in fahrenheit:, Exercise2_1 Input, JOptionPane.QUES
2、TION_MESSAGE); double fahrenheit = Double.parseDouble(fahrenheitString); double celsius = (5.0 / 9.0) * (fahrenheit - 32); System.out.println(The temperature is + celsius + in Celsius); System.exit(0); 2.7編寫程序?qū)⒋髮懽帜皋D(zhuǎn)換為小寫字母,該字符在源代碼ASCII中指定為直接量。public class Exercise2_7 public static void main(String ar
3、gs) char uppercase = F; int offset = (int)a - (int)A; char lowercase = (char)(int)uppercase + offset); System.out.print(The lowercase letter is + lowercase); 3.1 (三角形有效性驗(yàn)證)讀入三角形的三條邊并確定輸入是否有效。如果任意兩條邊和大于第三邊則輸入有效。import javax.swing.JOptionPane;public class Exercise3_1 public static void main(String arg
4、s) String numberString = JOptionPane.showInputDialog(null, Enter the first edge length (double), Exercise3_1 Input, JOptionPane.QUESTION_MESSAGE); double edge1 = Double.parseDouble(numberString); numberString = JOptionPane.showInputDialog(null, Enter the second edge length (double), Exercise3_1 Inpu
5、t, JOptionPane.QUESTION_MESSAGE); / Convert string to double double edge2 = Double.parseDouble(numberString); numberString = JOptionPane.showInputDialog(null, Enter the third edge length (double), Exercise3_1 Input, JOptionPane.QUESTION_MESSAGE); double edge3 = Double.parseDouble(numberString); Syst
6、em.out.println(Can edges + edge1 + , + edge2 + , and + edge3 + form a triangle? + ( (edge1 + edge2 edge3) & (edge1 + edge3 edge2) & (edge2 + edge3 edge1); System.exit(0); 4.1 (千克轉(zhuǎn)換成磅)編一個顯示下列表格的程序(1千克為2.2磅)(1kilogram = 2.2 pounds)KilogramsPounds12.236.6197433.4199437.8public class Exercise3_8 public
7、static void main(String args) System.out.println(kilogramsttpounds); System.out.println(-); int kilograms = 1; for (int i = 1; i = 100; kilograms += 2, i+) System.out.println(kilograms + tt + kilograms * 2.2); 4.18 用嵌套的循環(huán)語句,分別編寫程序打印下列圖案。Pattern 111 21 2 31 2 3 41 2 3 4 51 2 3 4 5 6Pattern 21 2 3 4 5
8、 61 2 3 4 51 2 3 41 2 31 2 /* Print Pattern I */public class Exercise3_23 public static void main(String args) for (int i = 1; i = 6; i+) for (int j = 1; j = i; j+) System.out.print(j + ); System.out.println(); /pattern 2public class test public static void main(String args) for (int i = 1; i = 6; i
9、+) for (int j = 1; j = A & c num2) double temp = num1; num1 = num2; num2 = temp; if (num2 num3) double temp = num2; num2 = num3; num3 = temp; if (num1 num2) double temp = num1; num1 = num2; num2 = temp; System.out.println(The sorted numbers are + num1 + + num2 + + num3); 6.1讀入10個數(shù)字,計算它們的平均值并且找出有多少個數(shù)
10、字在平均值之上。import javax.swing.*;public class Exercise5_1 public static void main(String args) double numbers = new double10; double sum = 0; for (int i = 0; i numbers.length; i+) String s = JOptionPane.showInputDialog(Enter a number: ); numbersi = Double.parseDouble(s); sum += numbersi; double average
11、= sum / 10; int countGreater = 0; for (int i = 0; i average) countGreater+; System.out.println(The number of values greater than the average is + countGreater); System.exit(0); 6.5讀入10個數(shù)并且顯示其中相互不同的數(shù)。提示:讀入一個數(shù),如果它是新數(shù),則把它存儲在數(shù)組中;如果數(shù)組中已有該數(shù),則把它丟棄。輸入結(jié)束后,數(shù)組中的數(shù)都是不同的數(shù)。public class Exercise6_5 public static vo
12、id main(String args) int numbers = new int10; int size = 0; for (int i = 0; i numbers.length; i+) String s = JOptionPane.showInputDialog(null, Enter an integer); int value = Integer.parseInt(s); boolean isInArray = false; for (int j = 0; j (Circle1)o).getRadius() return 1; else if (getRadius() (Cyli
13、nder1)o).findVolume() return 1; else if (findVolume() 0) return o1; else return o2; 10.編寫一個方法,返回對象組中最大的對象。(查找最大的對象)import java.util.Date;public class Exercise10_9 static int i; public Exercise10_9() public static void main(String args) String strings = CS, Math, Biol, Chem, Phys, Buss, Law, Educ, El
14、ec Engr, Mech Engr; Integer list = new Integer10; Date dates = new Date10; for (int i = 0; i list.length; i+) listi = new Integer(int)(Math.random() * 100); for (int i = 0; i list.length; i+) datesi = new Date(); System.out.println(Max string is + max(strings); System.out.println(Max integer is + ma
15、x(list); System.out.println(Max circle is + max(dates); public static Object max(Object a) Comparable max = (Comparable)a0; for (int i = 1; i a.length; i+) if (pareTo(ai) 0) max = (Comparable)ai; return max; 11.1編寫程序,利用Rational類計算下述級數(shù)的和:/ Exercise11_1.java: Use the Rational classpublic class Exercis
16、e11_1 public static void main(String args) final int N = 100; Rational sum = new Rational(); for (int i = 1; i = N; i+) sum = sum.add(new Rational(i - 1, i); System.out.println(The sum of the first series is + sum + = + sum.doubleValue(); 17.1編寫一個程序,利用異常處理方法處理非數(shù)值操作數(shù),然后在編寫一個程序,不適用異常處理方法達(dá)到同樣的目的。程序推出前應(yīng)
17、該顯示一條信息,通知用戶發(fā)生了操作數(shù)類型錯誤。/ Exercise17_1.java: Using( NumberFormatException異常)public class Exercise17_1 public static void main (String args) int num1, num2, result = 0; if (args.length != 3) System.out.println( please use java operand1 operator operand2); System.exit(0); try num1 = Integer.parseInt(args0); catch (NumberFormatException ex) System.out.println(Wrong Input: + args0
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 中國雞蛋深加工項(xiàng)目創(chuàng)業(yè)計劃書
- 中國尿鈣目測試紙項(xiàng)目創(chuàng)業(yè)計劃書
- 中國高頻手術(shù)電刀項(xiàng)目創(chuàng)業(yè)計劃書
- 中國AIDC項(xiàng)目創(chuàng)業(yè)計劃書
- 餐飲加盟店加盟商培訓(xùn)合同范本
- 網(wǎng)絡(luò)小額貸款逾期催收協(xié)議
- 2025數(shù)字化圖書借閱點(diǎn)加盟合同正式版
- 2025茶葉采購合同范本 采購合同范本
- 沒有合同怎么網(wǎng)簽協(xié)議書
- 基層競聘考試題庫及答案
- 血液透析患者皮膚護(hù)理
- 2025年家庭照護(hù)者、健康照護(hù)師崗位專業(yè)技能資格知識考試題(附答案)
- 智能醫(yī)療影像輔助診斷系統(tǒng)技術(shù)要求和測試評價方法
- 護(hù)欄安裝工作總結(jié)
- 小區(qū)弱電施工組織設(shè)計及施工方案
- 工業(yè)機(jī)器人系統(tǒng)操作員(中級) 課件 劉志輝 項(xiàng)目1 機(jī)械系統(tǒng)裝調(diào)
- 煤礦心理疏導(dǎo)培訓(xùn)課件
- 綠色城市旅游麗江古城景區(qū)介紹
- 2025屆山西省長治市市級名校中考生物全真模擬試題含解析
- MODS病人監(jiān)測與護(hù)理
- 2025年中化學(xué)生態(tài)環(huán)境有限公司招聘筆試參考題庫含答案解析
評論
0/150
提交評論