accp6.0java1第九章上机练习(Accp6.0java1 ninth chapter practice on the computer)

上传人:hs****ma 文档编号:498001672 上传时间:2023-07-16 格式:DOC 页数:12 大小:32.50KB
返回 下载 相关 举报
accp6.0java1第九章上机练习(Accp6.0java1 ninth chapter practice on the computer)_第1页
第1页 / 共12页
accp6.0java1第九章上机练习(Accp6.0java1 ninth chapter practice on the computer)_第2页
第2页 / 共12页
accp6.0java1第九章上机练习(Accp6.0java1 ninth chapter practice on the computer)_第3页
第3页 / 共12页
accp6.0java1第九章上机练习(Accp6.0java1 ninth chapter practice on the computer)_第4页
第4页 / 共12页
accp6.0java1第九章上机练习(Accp6.0java1 ninth chapter practice on the computer)_第5页
第5页 / 共12页
点击查看更多>>
资源描述

《accp6.0java1第九章上机练习(Accp6.0java1 ninth chapter practice on the computer)》由会员分享,可在线阅读,更多相关《accp6.0java1第九章上机练习(Accp6.0java1 ninth chapter practice on the computer)(12页珍藏版)》请在金锄头文库上搜索。

1、accp6.0java1第九章上机练习(Accp6.0java1 ninth chapter practice on the computer)Exercise 1: maintain an orderly list of booksImport java.util.Scanner;/ * * insert books in sequence* /Public class Book Public static void main (String args) String books = new String, Computer, Hibernate, Java, Struts;String n

2、ewBooks = new Stringbooks.length+1; / / the book into the arrayString = book; / / keep a book from the user nameInt index = books.length; / / save new insertion position/ / output into the results beforeSystem.out.print (array before insertion:);For (int i = 0; I books.length; i+) System.out.print (

3、booksi+ );/ / copy in the books array elements to the array of newBooksFor (int i = 0; I books.length; i+) NewBooksi = booksi;The input / book nameScanner input = new Scanner (System.in);System.out.print (n, enter a new book name:);Book = input.nextLine ();Find new location / /For (int i = 0; I 0) I

4、ndex = i;Break;For (int i = newBooks.length-1; I index; i-) NewBooksi = newBooksi-1; the element beginning with the /index subscript moves one position laterNewBooksindex = book; / / new elements in the index position/ / output after insertion of the resultsSystem.out.print (insert array: );For (int

5、 i = 0; I newBooks.length; i+) System.out.print (newBooksi+ );Exercise 2: calculate the average score of a classImport java.util.Scanner;/ * *Calculate the average score of a class* /Public class AvgScore Public static void main (String args) Int score = new int4; / / array performanceFloat sum = 0.

6、0F; / / the sum of scoresFloat average = 0.0F; / / average value/ / loop input student achievementScanner input = new Scanner (System.in);System.out.println (please enter the results of 4 participants);For (int i = 0; I score.length; i+) System.out.print (+ + (i+1) + students achievement:;Scorei = i

7、nput.nextInt ();Sum = sum + scorei; / / cumulative scoreAverage = sum / score.length; / / averageSystem.out.println (the average score of participants is: + average);Exercise 3: enter the number of lines, print right triangleImport java.util.Scanner;/ * * enter the number of lines and print right tr

8、iangles* /Public class RTriAngle Public static void main (String args) Int rows = 0; / / triangle line numberSystem.out.print (enter the right triangle row number:);Scanner input = new Scanner (System.in);Rows = input.nextInt ();Print / right triangleFor (int i = 1; I rows; i+) For (int j = 1; J = 1, -)for (int i = 1, j = n-1; i + +) system.o

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 高等教育 > 其它相关文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号