Java黑皮书课后题第10章:**10.9(Course类)如下改写Course类

您所在的位置:网站首页 couse的意思 Java黑皮书课后题第10章:**10.9(Course类)如下改写Course类

Java黑皮书课后题第10章:**10.9(Course类)如下改写Course类

#Java黑皮书课后题第10章:**10.9(Course类)如下改写Course类| 来源: 网络整理| 查看: 265

Java黑皮书课后题第7章:**7.23(游戏:储物柜难题)一个学校有100个储物柜和100个学生。所有的储物柜在上学的第一天都是关着的。…在所有学生都经过教学楼并且改变柜子之后,哪些柜子是开着的?

晓峰沧桑: 只要逻辑没问题,代码怎么写都行!表情包

Java黑皮书课后题第7章:*7.22(计算一个字符串中大写字母的数目)编写程序,从命令行输入一个字符串,然后显示字符串中大写字母的数目

晓峰沧桑: 这道题是让你从命令行中传参,你题意都理解错了。而且让你求大写字母的个数,你这求的是小写的个数,并且 Character 类本来就在 java.lang 中,根本不需要显式导入

Java黑皮书课后题第7章:**7.19(是否排好序了?)编写以下方法,如果参数中的list数组已经排好序了则返回true。编写一个测试程序,提示用户输入一个列表,显示该列表是否已经排好序

晓峰沧桑: 题目说是,数组已经按照升序排好,则返回 true ,看我如何优化你的代码 [code=java] import java.util.Scanner; public class ComprehensiveExercise19 { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("Enter the size of the list: "); int[] list = new int[input.nextInt()]; System.out.print("Enter the contents of the list: "); for (int i = 0; i < list.length; i++) list[i] = input.nextInt(); System.out.print("The list has " + list.length + " integers "); for (int each : list) System.out.print(each + " "); System.out.println("\nThe list is " + (isSorted(list) ? "already" : "not") + " sorted"); input.close(); } public static boolean isSorted(int[] list) { boolean isSorted = true; for (int i = 0; i < list.length - 1; i++) if (list[i] > list[i + 1]) { isSorted = false; break; } return isSorted; } } [/code]

Java黑皮书课后题第7章:**7.17(对学生排序)编写一个程序,提示用户输入学生个数、学生姓名和他们的成绩,然后按照学生成绩的降序打印学生的姓名。假定姓名是不包含空格的字符,使用next()读取

晓峰沧桑: 看我用你一半的代码量解决这道题: [code=java] import java.util.Scanner; public class ComprehensiveExercise17 { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("输入学生个数:"); int numbers = input.nextInt(); String[] names = new String[numbers]; int[] scores = new int[numbers]; for (int i = 0; i < numbers; i++) { System.out.println("输入第 " + (i + 1) + " 个学生的姓名:"); names[i] = input.next(); System.out.println("输入 " + names[i] + " 的分数:"); scores[i] = input.nextInt(); } for (int i = 0; i < numbers - 1; i++) { for (int j = i + 1; j < numbers; j++) { if (scores[j] > scores[i]) { int tempScore = scores[i]; scores[i] = scores[j]; scores[j] = tempScore; String tempName = names[i]; names[i] = names[j]; names[j] = tempName; } } } for (String each : names) { System.out.print(each + " "); } input.close(); } } [/code]

Java黑皮书课后题第7章:**7.3(计算数字的出现次数)编写程序,读取1到100之间的整数,然后计算每个数出现的次数。假定输入0表示结束

晓峰沧桑: 你題意理解錯了吧,不應該是用戶每輸入一個值,數組就動態擴展一次嗎?[code=java] Scanner input = new Scanner(System.in); int startLength = 1, inputValue; int[] intArray, tempArray = new int[startLength]; System.out.println("Enter the integers between 1 and 100: "); do { inputValue = input.nextInt(); if (inputValue != 0) { intArray = new int[startLength]; intArray[startLength - 1] = inputValue; } else { intArray = new int[startLength - 1]; intArray[startLength - 2] = inputValue; } for (int j = 0; j < startLength - 1; j++) intArray[j] = tempArray[j]; tempArray = intArray; startLength++; } while (inputValue != 0); [/code]



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3