JAVA入門練習(xí)50題含答案_第1頁
JAVA入門練習(xí)50題含答案_第2頁
JAVA入門練習(xí)50題含答案_第3頁
JAVA入門練習(xí)50題含答案_第4頁
JAVA入門練習(xí)50題含答案_第5頁
已閱讀5頁,還剩31頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

1、【程序1】題目:古典問題:有一對兔子,從出生后第 3個(gè)月起每個(gè)月都生一對兔子,小兔子長到第三個(gè)月后每個(gè)月 又生一對兔子,假如兔子都不死,問每個(gè)月的兔子總數(shù)為多少?這是一個(gè)菲波拉契數(shù)列問題public class lianxi01 public static void main(String args) System.out.println("第 1 個(gè)月的兔子對數(shù):1");System.out.println("第 2 個(gè)月的兔子對數(shù):1");int f1 = 1, f2 = 1, f, M=24;for(int i=3; i<=M; i+) f

2、=f2 = f1 + f2;f1 = f;System.out.println("第"+ i +"個(gè)月的兔子對數(shù):"+f2);【程序2】題目:判斷101-200之間有多少個(gè)素?cái)?shù),并輸出所有素?cái)?shù)。程序分析:判斷素?cái)?shù)的方法:用一個(gè)數(shù)分別去除2到sqrt(這個(gè)數(shù)),如果能被整除,則表明此數(shù)不是素?cái)?shù),反之是素?cái)?shù)。public class lianxi02 public static void main(String args) int count = 0;for(int i=101; i<200; i+=2) boolean b = false;for(i

3、nt j=2; j<=Math.sqrt(i); j+)if(i % j = 0) b = false; break; else b = true; if(b = true) count +;System.out.println(i ); System.out.println("素?cái)?shù)個(gè)數(shù)是:"+ count);【程序3】題目:打印出所有的"水仙花數(shù)",所謂"水仙花數(shù)"是指一個(gè)三位數(shù),其各位數(shù)字立方和等于該數(shù)本身。例如:153是一個(gè)"水仙花數(shù)",因?yàn)?53=1的三次方+ 5的三次方+ 3的 三次方。public

4、 class lianxi03 public static void main(String args) int b1, b2, b3;for(int m=101; m<1000; m+) b3 = m /100;b2 = m % 100 / 10;b1 = m %10;if(b3*b3*b3 + b2*b2*b2 + b1*b1*b1) = m) System.out.println(m+"是一個(gè)水仙花數(shù)");)【程序4】題目:將一個(gè)正整數(shù)分解質(zhì)因數(shù)。例如:輸入90打印出90=2*3*3*5 。程序分析:對n進(jìn)行分解質(zhì)因數(shù),應(yīng)先找到一個(gè)最小的質(zhì)數(shù)k,然后按下述步驟完

5、成:(1)如果這個(gè)質(zhì)數(shù)恰等于n,則說明分解質(zhì)因數(shù)的過程已經(jīng)結(jié)束,打印出即可。(2)如果n <> k,但n能被k整除,則應(yīng)打印出 k的值,并用n除以k的商,作為新的正整數(shù) 你n,重復(fù)執(zhí)行第一步。(3)如果n不能被k整除,則用k+1作為k的值,重復(fù)執(zhí)行第一步。import java.util.*;public class lianxi04public static void main(String args) Scanner s = new Scanner(System.in);System.out.print("請鍵入一個(gè)正整數(shù):");int n = s.next

6、Int();int k=2;System.out.print(n + "=");while(k <= n) if(k = n) System.out.println(n);break;else if( n % k = 0) System.out.print(k + "*");n = n / k; else k+;【程序5】題目:利用條件運(yùn)算符的嵌套來完成此題:學(xué)習(xí)成績>=90分的同學(xué)用A表示,60-89分之間的用B表不,60分以下的用C表不。import java.util.*;public class lianxi05 public sta

7、tic void main(String口 args) int x;char grade;Scanner s = new Scanner(System.in);System.out.print("請輸入一個(gè)成績:");x = s.nextInt();grade = x >= 90 ? 'A':x >= 60 ? 'B':'C'System.out.println("等級為:"+grade);)【程序6】題目:輸入兩個(gè)正整數(shù) m和n,求其最大公約數(shù)和最小公倍數(shù)。/*在循環(huán)中,只要除數(shù)不等于0,用較

8、大數(shù)除以較小的數(shù),將小的一個(gè)數(shù)作為下一輪循環(huán)的大數(shù),取得的余數(shù)作為下一輪循環(huán)的較小的數(shù),如此循環(huán)直到較小的數(shù)的值為0,返回較大的數(shù),此數(shù)即為最大公約數(shù),最小公倍數(shù)為兩數(shù)之積除以最大公約數(shù)。* /import java.util.*;public class lianxi06 public static void main(String口 args) int a ,b,m;Scanner s = new Scanner(System.in);System.out.print("鍵入一個(gè)整數(shù):");a = s.nextInt();System.out.print("再

9、鍵入一個(gè)整數(shù):");b = s.nextInt();deff cd = new deff();m = cd.deff(a,b);int n = a * b / m;System.out.println("最大公約數(shù):"+ m);System.out.println("最小公倍數(shù):"+ n);)class deffpublic int deff(int x, int y) int t;if(x < y) t = x;x = y;y = t; ) while(y != 0) if(x = y) return x; else int k = x

10、 % y;x = y;y = k;) return x;)【程序71題目:輸入一行字符,分別統(tǒng)計(jì)出其中英文字母、空格、數(shù)字和其它字符的個(gè)數(shù)。import java.util.*;public class lianxi07 public static void main(String args) int digital = 0;int character = 0;int other = 0;int blank = 0;char ch = null;Scanner sc = new Scanner(System.in);String s = sc.nextLine();ch = s.toCharA

11、rray();for(int i=0; i<ch.length; i+) if(ch >= '0' && ch <= '9') digital +; else if(ch >= 'a' && ch <= 'z') | ch > 'A' && ch <= 'Z') character +; else if(ch = ' ') blank +; else other +; System.out.pr

12、intln("數(shù)字個(gè)數(shù):"+ digital); System.out.println("英文字母個(gè)數(shù):"+ character); System.out.println("空格個(gè)數(shù):"+ blank); System.out.println("其他字符個(gè)數(shù):"+ other ); 【程序8題目:求 s=a+aa+aaa+aaaa+aa.aB勺值,其中 a是一個(gè)數(shù)字。例如 時(shí)共有5個(gè)數(shù)相加),幾個(gè)數(shù)相加有鍵盤控制。import java.util.*;public class lianxi08 public sta

13、tic void main(String口 args) long a , b = 0, sum = 0;Scanner s = new Scanner(System.in);System.out.print("輸入數(shù)字 a 的值:");a = s.nextInt();System.out.print("輸入相加的項(xiàng)數(shù):");int n = s.nextInt();int i = 0;while(i < n) b = b + a; sum = sum + b;a = a * 10;+ i;System.out.println(sum);【程序9】題目

14、:一個(gè)數(shù)如果恰好等于它的因子之和,這個(gè)數(shù)就稱為冶程 找出1000以內(nèi)的所有完數(shù)。public class lianxi09 public static void main(String口 args) System.out.println("1 到 1000 的完數(shù)有: ");for(int i=1; i<1000; i+) int t = 0;for(int j=1; j<= i/2; j+) if(i % j = 0) t = t + j;if(t = i) System.out.print(i + "");2+22+222+2222+22

15、222(此"。例如 6=1+2+3.編 【程序10題目:一球從100米高度自由落下,每次落地后反跳回原高度的一半;再落下,求它在 第10次落地時(shí),共經(jīng)過多少米?第10次反彈多高?public class lianxi10 public static void main(String args) double h = 100,s = 100;for(int i=1; i<10; i+) s = s + h;h = h / 2;)System.out.println("經(jīng)過路程:"+ s);System.out.println("反彈高度:"

16、+ h / 2);)【程序11題目:有1、2、3、4四個(gè)數(shù)字,能組成多少個(gè)互不相同且無重復(fù)數(shù)字的三位數(shù)?都是多少?public class lianxi11 public static void main(String args) int count = 0;for(int x=1; x<5; x+) for(int y=1; y<5; y+) for(int z=1; z<5; z+) if(x != y && y != z && x != z) count +;System.out.println(x*100 + y*10 + z );)S

17、ystem.out.println("共有"+ count + "個(gè)三位數(shù)");【程序題目:企業(yè)發(fā)放的獎(jiǎng)金根據(jù)利潤提成。利潤(I)低于或等于10萬元時(shí),獎(jiǎng)金可提10%;利潤高于10萬元,低于20萬元時(shí),低于10萬元的部分按10%提成,高于10萬元的部分,可 可提成7.5%; 20萬到40萬之間時(shí),高于 20萬元的部分,可提成 5%; 40萬到60萬之間時(shí) 高于40萬元的部分,可提成3%;60萬到100萬之間時(shí),高于60萬元的部分,可提成1.5%, 高于100萬元時(shí),超過100萬元的部分按1%提成,從鍵盤輸入當(dāng)月利潤,求應(yīng)發(fā)放獎(jiǎng)金總 數(shù)?import ja

18、va.util.*;public class lianxi12 public static void main(String口 args) double x = 0,y = 0;System.out.print("輸入當(dāng)月利潤(萬):");Scanner s = new Scanner(System.in);x = s.nextInt();if(x > 0 && x <= 10) y = x * 0.1; else if(x > 10 && x <= 20) y = 10 * 0.1 + (x - 10) * 0.07

19、5; else if(x > 20 && x <= 40) y = 10 * 0.1 + 10 * 0.075 + (x - 20) * 0.05; else if(x > 40 && x <= 60) y = 10 * 0.1 + 10 * 0.075 + 20 * 0.05 + (x - 40) * 0.03; else if(x > 60 && x <= 100) y = 20 * 0.175 + 20 * 0.05 + 20 * 0.03 + (x - 60) * 0.015; else if(x &g

20、t; 100) y = 20 * 0.175 + 40 * 0.08 + 40 * 0.015 + (x - 100) * 0.01;System.out.println("應(yīng)該提取的獎(jiǎng)金是"+ y + "萬");【程序13題目:一個(gè)整數(shù),它加上100后是一個(gè)完全平方數(shù),再加上168又是一個(gè)完全平方數(shù),請問該數(shù)是多少?public class lianxi13 public static void main(String args) for(int x =1; x<100000; x+) if(Math.sqrt(x+100) % 1 = 0) i

21、f(Math.sqrt(x+268) % 1 = 0) System.out.println(x + "加100是一個(gè)完全平方數(shù),再加168又是一個(gè)完全平方數(shù) ");) )/*按題意循環(huán)應(yīng)該從-100開始(整數(shù)包括正整數(shù)、負(fù)整數(shù)、零) ,這樣會(huì)多一個(gè)滿足條件的 數(shù)-99。但是我看到大部分人解這道題目時(shí)都把題中的整數(shù)”理解成正整數(shù),我也就隨大流了。*/【程序14題目:輸入某年某月某日,判斷這一天是這一年的第幾天?import java.util.*;public class lianxi14 public static void main(String args) int y

22、ear, month, day;int days = 0;int d = 0;int e;input fymd = new input();do e = 0;System.out.print("輸入年:");year =fymd.input();System.out.print("輸入月:");month = fymd.input();System.out.print("輸入天:");day = fymd.input();if (year < 0 | month < 0 | month > 12 | day <

23、 0 | day > 31) System.out.println("輸入錯(cuò)誤,請重新輸入!");e=1 ;while( e=1);for (int i=1; i <month; i+) switch (i) case 1:case 3:case 5:case 7:case 8:case 10:case 12:days = 31;break;case 4:case 6:case 9:case 11:days = 30;break;case 2:if (year % 400 = 0) | (year % 4 = 0 && year % 100 !=

24、 0) days = 29; else days = 28;)break;)d += days;)System.out.println(year + "-" + month + "-" + day + " 是這年的第"+ (d+day) + "天。");)class inputpublic int input() int value = 0;Scanner s = new Scanner(System.in);value = s.nextInt();return value;)【程序15題目:輸入三個(gè)整數(shù)x,y,z

25、,請把這三個(gè)數(shù)由小到大輸出。import java.util.*;public class lianxi15 public static void main(String口 args) input fnc = new input();int x=0, y=0, z=0;System.out.print("輸入第一個(gè)數(shù)字:");x = fnc.input();System.out.print("輸入第二個(gè)數(shù)字:");y = fnc.input();System.out.print("輸入第三個(gè)數(shù)字:");z = fnc.input();

26、if(x > y) int t = x;x = y;y = t;if(x > z) int t = x;x = z;z = t;if(y > z) int t = y;y = z;z = t;System.out.println("三個(gè)數(shù)字由小到大排列為:"+x + " " + y + " " + z);class inputpublic int input() int value = 0;Scanner s = new Scanner(System.in);value = s.nextInt();return va

27、lue;【程序16題目:輸出9*9 口訣。public class lianxi16 public static void main(String args) for(int i=1; i<10; i+) for(int j=1; j<=i; j+) System.out.print(j + "*" + i + "=" + j*i + "");if(j*i<10)System.out.print(" ");System.out.println();【程序17題目:猴子吃桃問題:猴子第一天摘下若干個(gè)

28、桃子,當(dāng)即吃了一半,還不癮,又多吃了一個(gè)第二天早上又將剩下的桃子吃掉一半,又多吃了一個(gè)。以后每天早上都吃了前一天剩下的一半零一個(gè)。到第10天早上想再吃時(shí),見只剩下一個(gè)桃子了。求第一天共摘了多少。public class lianxi17 public static void main(String args) int x = 1;for(int i=2; i<=10; i+) x = (x+1)*2;System.out.println("猴子第一天摘了" + x + "個(gè)桃子");【程序18題目:兩個(gè)乒乓球隊(duì)進(jìn)行比賽,各出三人。甲隊(duì)為 a,b,c

29、三人,乙隊(duì)為x,y,z三人。已抽簽決 定比賽名單。有人向隊(duì)員打聽比賽的名單。a說他不和x比,c說他不和x,z比,請編程序找出三隊(duì)賽手的名單。public class lianxi18 static char m = 'a', 'b', 'c' );static char n = 'x', 'y', 'z' );public static void main(String口 args) for (int i = 0; i < m.length; i+) for (int j = 0; j <

30、; n.length; j+) if (mi = 'a' && nj = 'x') continue; else if (mi = 'a' && nj = 'y') continue; else if (mi = 'c' && nj = 'x')| (mi = 'c' && nj = 'z') continue; else if (mi = 'b' && nj = '

31、;z')| (mi = 'b' && nj = 'y') continue; elseSystem.out.println(mi + " vs " + nj); 【程序19題目:打印出如下圖案(菱形)*public class lianxi19 public static void main(String args) int H = 7, W = 7;/高和寬必須是相等的奇數(shù)for(int i=0; i<(H+1) / 2; i+) for(int j=0; j<W/2-i; j+) System.out.

32、print("");)for(int k=1; k<(i+1)*2; k+) System.out.print('*');)System.out.println();)for(int i=1; i<=H/2; i+) for(int j=1; j<=i; j+) System.out.print(""); )for(int k=1; k<=W-2*i; k+) System.out.print('*');)System.out.println();)【程序20題目:有一分?jǐn)?shù)序列:2/1, 3/2,

33、5/3, 8/5, 13/8, 21/13.求出這個(gè)數(shù)列的前 20項(xiàng)之和。public class lianxi20 public static void main(String args) int x = 2, y = 1, t;double sum = 0;for(int i=1; i<=20; i+) sum = sum + (double)x / y;t = y;y = x;x = y + t;)System.out.println("前 20 項(xiàng)相加之和是:"+ sum);)【程序21題目:求 1+2!+3!+.+20!的和public class lian

34、xi21 public static void main(String args) long sum = 0;long fac = 1;for(int i=1; i<=20; i+) fac = fac * i;sum += fac;)System.out.println(sum);)【程序22題目:利用遞歸方法求 5!。public class lianxi22 public static void main(String args) int n = 5;rec fr = new rec();System.out.println(n+”! = "+fr.rec(n);clas

35、s recpublic long rec(int n) long value = 0 ;if(n =1 ) value = 1; else value = n * rec(n-1); return value;【程序23題目:有5個(gè)人坐在一起,問第五個(gè)人多少歲?他說比第 4個(gè)人大2歲。問第4個(gè)人歲數(shù), 他說比第3個(gè)人大2歲。問第三個(gè)人,又說比第 2人大兩歲。問第2個(gè)人,說比第一個(gè)人大 兩歲。最后問第一個(gè)人,他說是 10歲。請問第五個(gè)人多大?public class lianxi23 public static void main(String args) int age = 10;for(in

36、t i=2; i<=5; i+) age =age+2;System.out.println(age);【程序24題目:給一個(gè)不多于5位的正整數(shù),要求:一、求它是幾位數(shù),二、逆序打印出各位數(shù)字。 /使用了長整型最多輸入18位import java.util.*;public class lianxi24 public static void main(String口 args) Scanner s = new Scanner(System.in);System.out.print("請輸入一個(gè)正整數(shù):");long a = s.nextLong();String ss

37、 = Long.toString(a); char口 ch = ss.toCharArray(); int j=ch.length;System.out.println(a + " 是一個(gè)"+ j +" 位數(shù)。");System.out.print(" 按逆序輸出是:"); for(int i=j-1; i>=0; i-) System.out.print(chi); 【程序25題目:一個(gè)5位數(shù),判斷它是不是回文數(shù)。即 12321是回文數(shù),個(gè)位與萬位相同,十位與千 位相同。import java.util.*;public cl

38、ass lianxi25 public static void main(String口 args) Scanner s = new Scanner(System.in);int a;doSystem.out.print("請輸入一個(gè) 5位正整數(shù):");a = s.nextInt();while(a<1000011a>99999);String ss =String.valueOf(a);char口 ch = ss.toCharArray();if(ch0=ch4&&ch1=ch3)System.out.println(" 這是一個(gè)回文

39、數(shù)");else System.out.println("這不是一個(gè)回文數(shù)");/這個(gè)更好,不限位數(shù)import java.util.*;public class lianxi25a public static void main(String口 args) Scanner s = new Scanner(System.in);boolean is =true;System.out.print("請輸入一個(gè)正整數(shù):");long a = s.nextLong();String ss = Long.toString(a);char ch = ss

40、.toCharArray();int j=ch.length;for(int i=0; i<j/2; i+) if(chi!=chj-i-1)is=false;if(is=true)System.out.println("這是一個(gè)回文數(shù)");else System.out.println("這不是一個(gè)回文數(shù)");【程序26題目:請輸入星期幾的第一個(gè)字母來判斷一下是星期幾,如果第一個(gè)字母一樣,則繼續(xù)判斷第二個(gè)字母。import java.util.*;public class lianxi26 public static void main(Stri

41、ng args) getChar tw = new getChar();System.out.println("請輸入星期的第一個(gè)大寫字母:");char ch = tw.getChar();switch(ch) case 'M':System.out.println("Monday");break;case 'W:System.out.println("Wednesday");break;case 'F':System.out.println("Friday");break

42、;case 'T': System.out.println("請輸入星期的第二個(gè)字母:");char ch2 = tw.getChar();if(ch2 = 'U') System.out.println("Tuesday"); else if(ch2 = 'H') System.out.println("Thursday"); else System.out.println(" 無此寫法!");break;case 'S': System.out.p

43、rintln("請輸入星期的第二個(gè)字母:");char ch2 = tw.getChar();if(ch2 = 'U') System.out.println("Sunday"); else if(ch2 = 'A') System.out.println("Saturday"); else System.out.println(" 無此寫法!");break;default:System.out.println("無此寫法!");class getCharpub

44、lic char getChar() Scanner s = new Scanner(System.in);String str = s.nextLine();char ch = str.charAt(0);if(ch<'A' | ch>'Z') System.out.println(" 輸入錯(cuò)誤,請重新輸入");ch=getChar();return ch;【程序27題目:求100之內(nèi)的素?cái)?shù)使用除sqrt(n)的方法求出的素?cái)?shù)不包括 2和3public class lianxi27 public static void main

45、(String args) boolean b =false;System.out.print(2 + "");System.out.print(3 + "");for(int i=3; i<100; i+=2) for(int j=2; j<=Math.sqrt(i); j+) if(i % j = 0) b = false;break; elseb = true;if(b = true) System.out.print(i + " ");/該程序使用除1位素?cái)?shù)得2位方法,運(yùn)行效率高通用性差。public class

46、lianxi27a public static void main(String args) int a = new int2, 3, 5, 7;for(int j=0; j<4; j+)System.out.print(aj + "");boolean b =false;for(int i=11; i<100; i+=2) for(int j=0; j<4; j+) if(i % aj = 0) b = false;break; elseb = true;if(b = true) System.out.print(i + " ");【

47、程序28題目:對10個(gè)數(shù)進(jìn)行排序import java.util.*;public class lianxi28 public static void main(String口 args) Scanner s = new Scanner(System.in);int a = new int10;System.out.println(" 請輸入 10 個(gè)整數(shù):");for(int i=0; i<10; i+) ai = s.nextInt();for(int i=0; i<10; i+) for(int j=i+1; j<10; j+) if(ai >

48、 aj) int t = ai; ai = aj;aj = t;for(int i=0; i<10; i+) System.out.print(ai + "");【程序29題目:求一個(gè)3*3矩陣對角線元素之和import java.util.*;public class lianxi29 public static void main(String口 args) Scanner s = new Scanner(System.in);int口口 a = new int33;System.out.println(" 請輸入 9 個(gè)整數(shù):");for(i

49、nt i=0; i<3; i+) for(int j=0; j<3; j+) aij = s.nextInt();System.out.println(" 輸入的 3 * 3 矩陣是:");for(int i=0; i<3; i+) for(int j=0; j<3; j+) System.out.print(aij + "");System.out.println();int sum = 0;for(int i=0; i<3; i+) for(int j=0; j<3; j+) if(i = j) sum += ai

50、j;System.out.println("對角線之和是:"+ sum);【程序30題目:有一個(gè)已經(jīng)排好序的數(shù)組。現(xiàn)輸入一個(gè)數(shù),要求按原來的規(guī)律將它插入數(shù)組 中。/此程序不好,沒有使用折半查找插入import java.util.*;public class lianxi30 public static void main(String args) int a = new int1,2, 6, 14, 25, 36, 37,55;int b = new inta.length+1;intt1=0,t20;int i =0;Scanner s= new Scanner(Sys

51、tem.in);System.out.print("請輸入一個(gè)整數(shù):");int num = s.nextInt(); if(num >= aa.length-1) bb.length-1 = num; for(i=0; i<a.length; i+) bi = ai; else for(i=0; i<a.length; i+) if(num >= ai) bi = ai; else bi = num; break; for(int j=i+1; j<b.length; j+) bj = aj-1; for (i = 0; i < b.l

52、ength; i+) System.out.print(bi + ""); 【程序31 題目:將一個(gè)數(shù)組逆序輸出。 import java.util.*; public class lianxi31 public static void main(String args) Scanner s = new Scanner(System.in); int a = new int20;System.out.println("請輸入多個(gè)正整數(shù)(輸入 -1表示結(jié)束):");int i=0,j; do ai=s.nextInt(); i+; while (ai-1!

53、=-1); System.out.println("你輸入的數(shù)組為:");for(j=0; j<i-1; j+) System.out.print(aj+"");System.out.println("n 數(shù)組逆序車出為:");for( j=i-2; j>=0; j=j-1) System.out.print(aj+"");【程序32題目:取一個(gè)整數(shù)a從右端開始的47位。import java.util.*;public class lianxi32 public static void main(St

54、ring args) Scanner s = new Scanner(System.in);System.out.print("請輸入一個(gè)7位以上的正整數(shù):");long a = s.nextLong();String ss = Long.toString(a);char口 ch = ss.toCharArray();int j=ch.length;輸入錯(cuò)誤! ");截取從右端開始的 47 位是if (j<7)System.out.println( else System.out.println(""+chj-7+chj-6+chj-5+

55、chj-4); 【程序33題目:打印出楊輝三角形(要求打印出10行如下圖)11 12 13 36410105public class lianxi33 public static void main(String args) int a = new int1010;for(int i=0; i<10; i+) aii = 1;ai0 = 1;for(int i=2; i<10; i+) for(int j=1; j<i; j+) aij = ai-1j-1 + ai-1j;for(int i=0; i<10; i+) for(int k=0; k<2*(10-i)

56、-1; k+) System.out.print("");)for(int j=0; j<=i; j+) System.out.print(aij + "");)System.out.println();)【程序34題目:輸入3個(gè)數(shù)a,b,c ,按大小順序輸出。import java.util.Scanner;public class lianxi34 public static void main(String args) Scanner s = new Scanner(System.in);System.out.println(" 請

57、輸入 3 個(gè)整數(shù):");int a = s.nextInt();int b = s.nextInt();int c = s.nextInt();if(a < b) int t = a;a = b;b = t;)if(a < c) int t = a;a = c;c = t;)if(b < c) int t = b;b = c;c = t;)System.out.println("從大到小的順序輸出:");System.out.println(a + " " + b + " " + c);)【程序35題目:輸入數(shù)組,最大的與第一個(gè)元素交換,最小的與最后一個(gè)元素交換,輸出數(shù)組。import java.util.*;public class lianxi35 public static void main(String args) int N = 8;int a = new int N;Scanner s = new Scanner(System.in);int idx1 = 0, idx2 = 0;System.out.println(

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論