


下載本文檔
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
1、java 程序?qū)嵗?15 題附答案1、public class MyClass( private int vall,vaI2 ;public void myFun(int x,int y)vall=x;val2=y ;11 nSystem.out.println( The sum is: +(vall+val2);public static void main(String arg)MyClass MyObj=new MyClass();MyObj.myFun(l,2);運行結(jié)果如下:The sum is: 32、public class MyArray (public static void
2、 main(String args)int myArrayf;聲明數(shù)組myArray=new int10;創(chuàng)建數(shù)組System.outprintln( nIndextt Value'');for(int i=0; ivmyArray.length;i+)System.out.println(i+ * ftt * 1+my Array i);證明數(shù)組元素聯(lián)認初始化為 0/myArray 10=100;將產(chǎn)生數(shù)組越界異常 輸出:50503、public class Arrays( public static void main(String args) int al = ( 1,2
3、, 3, 4, 5 ;int a2;a2 = al;for(int i = 0; i < a2.1ength; i+) a2i+;for(int i = 0; i < al.length; i+) System.out.println( "al" + i + '' = " + ali);運行結(jié)果:al0 = 2all = 3al2 = 4al3 = 5al 4 = 6 4、 public class ArrayOfStringsDemo public static void main(String args); for (int i =
4、 0; i < String anArray = "String One", "String Two", "String Three" anArray.length; i+) System.out.println(anArrayi.toLowerCase(); 運行結(jié)果: string one string two string three 5、public class ArrayCopyDemo( public static void main(String args) char copyFrom = 'd',
5、 'e', 'c', 'a', f, f, 'e','i', 'n', 'a', f, 'e', 'd' char copyTo = new char7; System.arraycopy(copyFrom, 2, copyTo, 0, 7); System.out.println(new String(copyTo); J 運行結(jié)果 : caffeine6、 ex3_l-輸入一個年份,判斷它是不是閏年。-閏年:能被 4整除但不能被 100 整除,或者
6、能被 400整除。 import java.io.*;public class ex3_l(public static void main(String args) throws IOException(int year;boolean IsLeapYear;System.out.println("Enter the year:");BufferedReader in =new BufferedReader( new InputStreamReader(System.in);year=(new Integer(in.readLine().intValue();IsLeapY
7、ear=(year%4=0 && year% 100 != 0)ll(year%400 = 0);if (IsLeapYear)System.out.print(year);System.out.println( "is a leap year");elseSystem.out.print(year);System.out.println( "is not a leap year");7、輸入兩個整數(shù)比較大小import java.io.*;public class ex3_2(public static void main(String
8、 args)throws lOExceptionint x,y;BufferedReader in = new BufferedReader(new InputStreamReader(System.in);System.out.println("Enter x and y:n);x=(new Integer(in.readLine().intValue();y=(new Integer(in.readLine().intValue();if (x!=y)if (x>y) System.out.println("x>y n);elseSystem.out.pri
9、ntln(nx<yn);else System.out.println(nx=yn);80-89 分為 B 級;(0 對應(yīng)星期日 )8、已知一個學生的分數(shù),給出其分數(shù)等級。 90-100 分為 A 級;70-79分為C級;60-69分為D級;0-59分為E級public class IfElseDemo (public static void main(String args) (int testscore = 76;char grade;if (testscore >= 90) ( grade = 'A' )else if (testscore >= 80)
10、 ( grade = 'B' else if (testscore >= 70) ( grade = C; else if (testscore >= 60) ( grade = 'D' else grade = F; System.out.println("Grade = " + grade); J或public class Grade (public static char gradeLevel(double g)(int n = (int)Math.floor(g/10);switch (n)(case 10:case 9
11、: retum('A');case 8 : retum('B');case 7 : retum('C');case 6 : retum('D');default: retum('E');public static void main(String args)( System.out.println("gradeLevel(100)="+gradeLevel(100); System.out.println(,gradeLevel(95.5)="+gradeLevel(95.5);Sys
12、tem.out.println("gradeLevel(88)="+gradeLevel(88); System.out.println("gradeLevel(72)="+gradeLevel(72);System.out.println(',gradeLevel(68.5)="+gradeLevel(68.5); System.out.println("gradeLevel(60)="+gradeLevel(60);System.out.println(',gradeLevel(59.5)="+
13、gradeLevel(59.5); System.out.println("gradeLevel(35)="+gradeLevel(35);9、輸入 0? 6 之間的某一個整數(shù),然后把它轉(zhuǎn)換成星期輸出。 import java.io.*;public class ex3_3(public static void main(String args)throws lOExceptionint day;BufferedReader in =new BufferedReader(new InputStreamReader(System.in); day=(new Integer(i
14、n.readLine().intValue(); switch (day)(n1case 0: System.out.println( nSunday* 1);break;case 1: System.outprintln( nMonday* 1);break;case 2: System.outprintln( nTuesdayn); break;case 3: System.out.println( nWednesday n); break;case 4: System.outprintln( nThursday n); break;case 5: System.outprintln( n
15、Friday n); break;case 6: System.outprintln( nSaturday* 1); break; default:Sy stem .out.println( n Day out of range Sunday .Saturday 0 ); break; 10、打印九九乘數(shù)表 public class MultiTable ( public static void main(String args)(for (int i=l; iv=9;i+) ( for (int j=l; j<=i;j+)System, out. print。 ” +i+ ”*”+j+
16、 ” =” +i*j); S ystem.out.println();11、輸入一個整數(shù),輸出它所有的因數(shù) import java.io.*; public class ex3_7public static void main(String args) throws IOException( int n,k; BufferedReader in =new BufferedReader(new InputStreamReader(System.in); System.out.println("Enter a positive integer:"); n=(new Intege
17、r(in.readLine().intValue(); System.out.print( "Number” +n+" Factors ");for (k=l; k <= n; k+)if (n % k = 0) System.out.print(k + ""); System.out.println();12、計算數(shù)列 1,2,.,10 的和。 public class ex3_4public static void main(String args)int i=l, sum=0;while(i<=10) ( sum+=i; i+
18、;)S y stem.out .println(" sum="+sum);'13、輸入一個整數(shù),然后輸出它的翻轉(zhuǎn)形式import java.io.*;public class ex3_5(public static void main(String args)throws IOException( int n, right_digit, newnum = 0;BufferedReader in = new BufferedReader(new InputStreamReader(System.in);System.out.println("Enter th
19、e number:");n=(new Integer(in.readLine().intValue(); System.out.print(nThe number in reverse order is "); do right_digit = n % 10;System.out.print(right_digit); n/= 10;while (n != 0);System.out.println();14、public class BreakTest (public static void main( String args ) (String output =int i;for (i = l;i<= 10; i+) (if (i = 5 ) break; / break loop only if count = 5 output += i
溫馨提示
- 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)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025至2030布藝行業(yè)市場深度調(diào)研及發(fā)展趨勢與發(fā)展趨勢分析與未來投資戰(zhàn)略咨詢研究報告
- 改初一學霸的數(shù)學試卷
- 阜陽2024高三聯(lián)考數(shù)學試卷
- 高一聯(lián)考數(shù)學試卷
- 豐南區(qū)期末考試數(shù)學試卷
- 知識產(chǎn)權(quán)戰(zhàn)略在健身器材行業(yè)中的法律風險防范措施考核試卷
- 恩施州期末聯(lián)考數(shù)學試卷
- 贛州市一模理科數(shù)學試卷
- 印刷企業(yè)品牌形象塑造與傳播策略考核試卷
- 鳳凰教育小升初數(shù)學試卷
- 重點監(jiān)控藥品臨床應(yīng)用管理規(guī)范
- 信息安全應(yīng)急預(yù)案演練腳本
- 全國《法律職業(yè)資格考試》試卷一預(yù)熱階段同步訓練卷(附答案)
- DB11-509-2017房屋建筑修繕工程定案和施工質(zhì)量驗收規(guī)程
- 2022年丹東市元寶區(qū)社區(qū)工作者招聘筆試題庫及答案解析
- 藝術(shù)欣賞完整版課件全套ppt教程(最新)
- GB∕T 2518-2019 連續(xù)熱鍍鋅和鋅合金鍍層鋼板及鋼帶
- 教育培訓機構(gòu)輔導老師月度績效考核表(KPI)
- (高清正版)JJF(浙)1162-2019空氣熱老化試驗設(shè)備校準規(guī)范
- 國家開放大學《中國古代文學(B)(1)》章節(jié)測試參考答案
- 無機化學第4版下冊(吉大宋天佑)2019
評論
0/150
提交評論