Java第四章题
- 格式:docx
- 大小:22.88 KB
- 文档页数:4
java认证习题第04章有答案版OK该试题还有第03、05章1、what is the result when you compile and run the following code? C Class Example{Public static void main(String []args){System.out.println(3/0);}}Select all right answer:A a compiler errorB a runtime errorC /doc/3a1160281.htmlng.ArtithmeticException :/by zeroD infinity考察算术运算,分母为0 ,非法2、which results is true when you compile and run the following code?Bboolean b1=true; Boolean b2=falseSelect all right answer:A 、b1==b2 B、b1||b2 C、b1|&b2 D、b1&&b2考察逻辑运算,A返回false, C语法错误运算符没有连接操作,D返回false3、what is the result when you compile and run the following code? C Class Example{Public static void main(String []args){int i=1;int j;j=i++;System.out.print(i+”,”+j);}}Select all right answer:A、1,1 B。
1,2 C、2,1 D、2,2运算过程是:先把i赋给j,此时i=1,y=1,然后i自动加1,并把结果赋给I, 则i变为24、what is the result when you compile and run the following code? A Class Example{Public static void main(String []args){int x=5;boolean y=true;System.out.print(x<y);< bdsfid="102" p=""></y);<>}}Select all right answer:A、a compiler errorB、a running errorC、trueD、false考察关系运算,不能用0替代false5、what is the result when you compile and run the following code? A Class Example{Public static void main(String []args){Short s=new Short(“5”);Boolean b;// insert code here}}Which,inserted independently at //insert code here?,will compile ? B D Select all right answer:A b=(Number instanceof s);B b=(s instanceof Short);C b=s instanceof (Short);D b=(s instanceof Number);E b= s instanceof (Object);F b=(s instanceof String);考察instanceof运算符,A写反了,C.E语法错误F类型不兼容6、which of the following lines of code will compile without error? B CAint i=0;if (i) System.out.println(“Hi”);Bboolean b=true;boolean b2=true;if (b==b2) System.out.println(“so true”);Cint i=1;int j=2;if(i==1 || j==2)System.out.println(“OK”);Dint i=1;int j=2;if(i==1 &|j==2)System.out.println(“OK”);本题考察boolean表达式,A错在不能用数字充当boolean型值,D错在逻辑操作非法7、what is the result when you compile and run the following code? B D Class Example{Public static void main(String []args){Float f=new Float(4.2f);Float c;Double d=new Double(4.2);float f1=4.2f;c=f;}}Select all right answer:A f.equals(d)B c==fC c==dD c.equals(f)==比较内存地址,equals比较内容8、what is the result when you compile and run the following code? D Class Example{Public static void main(String []args){byte x=--64;byte y=--6;System.out.println(x/y+””+x%y);}}Select all right answer:A a compiler errorB a runtime errorC 10 4D 10 -49、what is the result when you compile and run the following code? G Class Example{public static void main(String []args){long x=42L;long x=44L;System.out.println(““+7+2+”“);System.out.println(foo()+x+5+”“);System.out.println(x+y+foo());}static String foo(){ return “foo”;}}Select all right answer:A 、9 foo 47 86 foo B、9 foo 47 4244foo C、9 foo 425 86 fooD、9 foo 425 4244 fooE、72 foo 47 86 fooF、72 foo 47 4244 fooG、72foo 425 86 foo H、72 foo 425 4244 foo I、compilation fails本题考察字符串连接,,两个操作数中有一个以上字符串就进行连接,俩操作数都是数值时做+运算10、what is the result when you compile and run the following code? A Class Example{public static void main(String []args){String s1=”Amit”;String s2=”Amit”;String s3=new String(“abcd”);String s4=new String(“abcd”);System.out.println(s1.equals(s2));System.out.println((s1==s2));System.out.println(s3.equals(s4));String s3=new String((s3==s4));}}Select all right answer:A true true true falseB true true true trueC true false true falseS1和S2内容一样,引用也一样,因为不是new的就都是从字符串池中取的,s3,s4内容一样,但不是指同一对象11、what is the result when you compile and run the following code? Bchar c=’c’;int i=10;double d=10;long l=1;String s=”Hello”Select all right answer:A c=c+iB s+=iC i+=sD c+s+=符号左侧应是字符串12、which of the following returns true when replace with *****? A Class Example{public static void main(String []args){Button b=new Button(“Button”);if(*******)System.out.println(“this is an instance of Button”);}}Select all right answer:A 、b instanceof Button B、Button instancof b C、b==Button D、Button==(Object)b 考察比较运算符,13、what is the result when you compile and run the following code? A import java.awt.*;Class Example{public static void main(String []args){try{Button[] var=new Button[5];System.out.println(var instanceof []);}catch(Exception e){System.out.println(“Exception thrown”);}}}Select all right answer:A a compiler errorB Exception thrownC trueD flaseE none of the above Instanceof右侧应该是类,接口或数组类型14、what is the result when you compile and run the following code? D 132import java.awt.*;Class Example{public static void main(String []args){int Output=10;boolean b1=false;if((b1==true)&&(Output+=10)==20)){System.out.println(“we are equal ”+Output);}elseSystem.out.println(“Not equal ”+Output);}}Select all right answer:A compile error ,attempting to perform binary comparison on logical data typeB Compilation and output of “we are equal 10”C compilation and output of “not equal 20”D compilation and o utput of “not equal 10”考察逻辑短路因为逻辑短路,所以(Output+=1没被执行15、what is the result when you compile and run the following code? F 145Class Example{ String s;public static void main(String []args){ Example ks=new Example();int j,i;i=ks.hai();j=ks.hello();S ystem.out.println(i+””+j);}int hai(){if((s==null)||(s.length()==0)) {return 10;}else return 0;}int hello(){if((s==null)||(s.length()==20)) {return 10;}else return 0;}}Select all right answer:A 10 10B 10 nullC 0 0D compilation errorE An exception in haiF an excepton in hello考察逻辑短路,|不属于短路运算,所以s.lengh()会被执行,因为s为null,所以抛出异常课后作业:1. Given:class Hexy {public static void main(String[] args) {Integer i = 42;String s = (i<40)?"life":(i>50)?"universe":"everything";System.out.println(s);}}What is the result?A. nullB. lifeC. universeD. everythingE. Compilation fails.F. An exception is thrown at runtime.Answer:3 D is correct. This is a ternary nested in a ternary with a little unboxing thrown in.Both of the ternary expressions are false.A, B, C, E, and F are incorrect based on the above.(Objective 7.6)2. Given:1. class Example {2. public static void main(String[] args) {3. Short s = 15;4. Boolean b;5. // insert code here6. }7. }Which, inserted independently at line 5, will compile? (Choose all that apply.)A. b = (Number instanceof s);B. b = (s instanceof Short);Self Test Answers 307C. b = s.instanceof(Short);D. b = (s instanceof Number);E. b = s.instanceof(Object);F. b = (s instanceof String);Answer:3 B and D correctly use boxing and instanceof together.A is incorrect because the operands are reversed. C and E use incorrect instanceof syntax.F is wrong because Short isn't in the same inheritance tree as String. (Objective 7.6)3. Given:1. class Comp2 {2. public static void main(String[] args) {3. float f1 = 2.3f;4. float[][] f2 = {{42.0f}, {1.7f, 2.3f}, {2.6f, 2.7f}};5. float[] f3 = {2.7f};6. Long x = 42L;7. // insert code here8. System.out.println("true");9. }10. }And the following five code fragments:F1. if(f1 == f2)F2. if(f1 == f2[2][1])F3. if(x == f2[0][0])F4. if(f1 == f2[1,1])F5. if(f3 == f2[2])What is true?A. One of them will compile, only one will be true.B. Two of them will compile, only one will be true.C. Two of them will compile, two will be true.D. Three of them will compile, only one will be true.E. Three of them will compile, exactly two will be true.F. Three of them will compile, exactly three will be true.308 Chapter 4: OperatorsAnswer:3 D is correct. Fragments F2, F3, and F5 will compile, and only F3 is true.A, B, C, E, and F are incorrect. F1 is incorrect because you can’t compare a primitive toan array. F4 is incorrect syntax to access an element of a two-dimensional array.(Objective 7.6)4. Given:class Fork {public static void main(String[] args) {if(args.length == 1 | args[1].equals("test")) {System.out.println("test case");} else {System.out.println("production " + args[0]);}}}And the command-line invocation:java Fork live2What is the result?A. test caseB. productionC. test case live2D. Compilation fails.E. An exception is thrown at runtime.Answer:3 E is correct. Because the short circuit (||) is not used, both operands are evaluated. Sinceargs[1] is past the args array bounds, an ArrayIndexOutOfBoundsException is thrown.A, B, C, and D are incorrect based on the above.(Objective 7.6)Self Test Answers 3095. Given:class Foozit {public static void main(String[] args) {Integer x = 0;Integer y = 0;for(Short z = 0; z < 5; z++)if((++x > 2) || (++y > 2))x++;System.out.println(x + " " + y);}What is the result?A. 5 1B. 5 2C. 5 3D. 8 1E. 8 2F. 8 3G. 10 2H. 10 3Answer:3 E is correct. The first two times the if test runs, both x and y are incremented once (thex++ is not reached until the third iteration). Starting with the third iteration of the loop,y is never touched again, because of the short-circuit operator.A, B, C, D, F, G, and H are incorrect based on the above.(Objective 7.6)6. Given:class Titanic {public static void main(String[] args) {Boolean b1 = true;boolean b2 = false;boolean b3 = true;if((b1 & b2) | (b2 & b3) & b3)System.out.print("alpha ");if((b1 = false) | (b1 & b3) | (b1 | b2))System.out.print("beta ");}310 Chapter 4: OperatorsWhat is the result?A. betaB. alphaC. alpha betaD. Compilation fails.E. No output is produced.F. An exception is thrown at runtime.Answer:3 E is correct. In the second if test, the leftmost expression is an assignment, nota comparison. Once b1 has been set to false, the remaining tests are all false.A, B, C, D, and F are incorrect based on the above.(Objective 7.6 )7. Given:class Feline {public static void main(String[] args) {Long x = 42L;Long y = 44L;System.out.print(" " + 7 + 2 + " ");System.out.print(foo() + x + 5 + " ");System.out.println(x + y + foo());}static String foo() { return "foo"; }}What is the result?A. 9 foo47 86fooB. 9 foo47 4244fooC. 9 foo425 86fooD. 9 foo425 4244fooE. 72 foo47 86fooF. 72 foo47 4244fooG. 72 foo425 86fooH. 72 foo425 4244fooI. Compilation fails.Self Test Answers 311Answer:3 G is correct. Concatenation runs from left to right, and if either operand is a String,the operands are concatenated. If both operands are numbers they are added together.Unboxing works in conjunction with concatenation.A, B, C, D, E, F, H, and I are incorrect based on the above. (Objective 7.6)8. Place the fragments into the code to produce the output 33. Note, you must use each fragmentexactly once.CODE:class Incr {public static void main(String[] args) {Integer x = 7;int y = 2;x ___ ___;___ ___ ___;___ ___ ___;___ ___ ___;System.out.println(x);}}FRAGMENTS:y y y yy x x-= *= *= *=Answer:class Incr {public static void main(String[] args) {Integer x = 7;int y = 2;312 Chapter 4: Operatorsx *= x;y *= y;y *= y;x -= y;System.out.println(x);}}Yeah, we know it’s kind of puzzle-y, but you might encounter something like it on the real exam.(Objective 7.6)9. Given:1. class Maybe {2. public static void main(String[] args) {3. boolean b1 = true;4. boolean b2 = false;5. System.out.print(!false ^ false);6. System.out.print(" " + (!b1 & (b2 = true)));7. System.out.println(" " + (b2 ^ b1));8. }9. }Which are true?A. Line 5 produces true.B. Line 5 produces false.C. Line 6 produces true.D. Line 6 produces false.E. Line 7 produces true.F. Line 7 produces false.Answer:3 A , D, and F is correct. The ^ (xor) returns true if exactly one operand is true. The! inverts the operand’s boolean value. On line 6 b2 = true is an assignment not acomparison, and it’s evaluated because & does not short-circuit it. ??B, C, and E are incorrect based on the above.(Objective 7.6)Self Test Answers 31310. Given:class Sixties {public static void main(String[] args) {int x = 5;int y = 7;System.out.print(((y * 2) % x));System.out.print(" " + (y % x));}}What is the result?A. 1 1B. 1 2C. 2 1D. 2 2E. 4 1F. 4 2G. Compilation fails.H. An exception is thrown at runtime.Answer:3 F is correct. The % (remainder a.k.a. modulus) operator returns the remainder of adivision operation.A, B, C, D, E, G, and H are incorrect based on the above.。
《疯狂Java讲义(第4版)》-----第4章【习题解答】【练习1】九九乘法表public class Multiplication_table {public static void main(String[]args){for(int i=1;i<=9;i++){for(int j=1;j<=i;j++){System.out.print(i+"X"+j+"="+(i*j));if(j!=i) System.out.print(",");}System.out.println();}}}【练习2】打印由"*"⽣成的等腰三⾓形import java.util.Scanner;public class test {public static void main(String[] args){Scanner scan=new Scanner(System.in);int n=scan.nextInt();for(int i=1;i<=n;i++){for(int j=1;j<=n-i;j++) System.out.print(" ");for(int j=1;j<=2*i-1;j++) System.out.print("*");System.out.println();}}}【练习3】⽤“*”打印⼀个圆//本程序依据x^2+y^2=r^2这个圆公式进⾏画圆import java.util.Scanner;import ng.Math;public class test{public static void main(String[] args){Scanner scan=new Scanner(System.in);double r=scan.nextDouble();for(double x=-r;x<=r;x+=2){ //此处i+=2,可以控制好更像圆,如果i++像椭圆double y=Math.sqrt(Math.pow(r, 2)-Math.pow(x, 2));for(double i=-r;i<=r;i++){//对于x坐标,遍历⼀边-r到r所有值,如果和y坐标之差的绝对值在0.5的误差范围内,我们就认为此处i=y,应该⼤⾐呢出点System.out.print((Math.abs(y-i)<=0.5 || Math.abs(-y-i)<=0.5)?'*':' ');}System.out.println();}}}输⼊输出样例:【练习4】通过字节截取实现String的substring⽅法⽅案⼀看了⽹上的各类版本,都没有实现题⽬要求,下⾯代码可以实现题⽬要求,实现和String的substring完全⼀样的功能。
第4张课后作业_数组知识点:一维数组、二维数组一、填空及选择:1.数组元素的小标总是从___0___开始。
2.对于数组int[][]={{1,2,3},{4,5,6}}来说,t.length等于__2____,t[0].length等于___3__。
3.已知数组a的定义为“int a[]={1,2,3,4,5};”,则a[2]=__3__,数组b的定义为“int b[]=newint[5];”,则b[2]=__ 0___,数组c的定义为“Object [] c=new Object[5];”,则c[2]=_____。
4.调用数组元素时,用__数组名__和__元素下标___来唯一确定数组中的元素。
5.下列___C__语句有错误A.int [] a;B.int [] b=new int[10];C. int []c=new int[];D.int d[]=null;6.下列___D__语句有错误A.int a[][]=new int[5][5];B.int [][] b=new int[5][5];C.int []c[]=new int[5][5];D.int [][]d=new int[5,5];7.关于下面的程序,正确的结论是___A__public class Demo1{public static void main(String [] args){int a[]=new int[5];boolean b[]=new boolean[5]; //布尔值自动初始化为falseSystem.out.println(a[1]);System.out.println(b[2]);}}A.运行结果为0 falseB.运行结果为1 trueC.程序无法编译D.可以通过编译但结果不确定二、编程题:1.定义一个整数定义的数组,求奇数个数和偶数个数。
2.用20个整数初始化数组,只是输出前10个数。
用break控制3.计算10~20的整数的平方值,将结果保存在一个数组中。
第4章1.假定乘坐飞机时,每位顾客可以免费托运20kg以内的行李,超过部分按每公斤收费1.2元,以下是相应的计算收费程序。
该程序存在错误,请找出。
public class Test{public static void main(String[] args) throws IOException{float w,fee;//以下代码为通过控制台交互输入行李重量InputStreamReader reader=new InputStreamReader(System.in);BufferedReader input=new BufferedReader(reader);System.out.println("请输入旅客的行李重量:");String temp=input.readLine();w = Float.parseFloat(temp); //字符串转换为单精度浮点型fee = 0;if ( w > 20);fee = (float)1.2 * (w-20);System.out.println("该旅客需交纳的托运费用:"+fee+"元");}}缺少import java.io.*; 语句2.有一条长的阶梯,如果每步2阶,则最后剩1阶,每步3阶则剩2阶,每步5阶则剩4阶,每步6阶则剩5阶,只有每步7阶的最后才刚好走完,一阶不剩,问这条阶梯最少共有多少阶?找出以下求解程序的错误所在。
public class Test{ public static void main(String[] args){int i;while(i%2==1&&i%3==2&&i%5==4&&i%6==5&&i%7==0) {i++;}System.out.println("这条阶梯最少有:"+i+"阶");}}1)变量i应进行初始化。
第一章:Java基础1.1 Java语言概述1.1.1 Java语言的起源1.1.2 Java语言的特点1.1.3 Java语言的运行环境1.1.4 Java语言的开发工具1.2 Java语法基础1.2.1 数据类型1.2.2 变量和常量1.2.3 运算符1.2.4 控制语句1.3 面向对象编程1.3.1 类和对象1.3.2 构造方法1.3.3 继承1.3.4 多态1.3.5 封装1.4 异常处理1.4.1 异常的概念1.4.2 异常的捕获与处理1.4.3 自定义异常1.5 Java集合框架1.5.1 List接口1.5.2 Set接口1.5.3 Map接口1.5.4 Collection类1.5.5 Iterator接口1.5.6 Collection框架的常用类第二章:Java进阶2.1 Java多线程2.1.1 线程的概念2.1.2 线程的创建与运行2.1.3 线程同步2.1.4 线程通信2.2 Java网络编程2.2.1 URL类2.2.2 Socket编程2.2.3 HTTP协议2.3 Java数据库编程2.3.1 JDBC概述2.3.2 JDBC连接数据库2.3.3 JDBC查询与更新2.3.4 JDBC事务管理2.4 Java设计模式2.4.1 单例模式2.4.2 工厂模式2.4.3 代理模式2.4.4 装饰者模式2.4.5 策略模式第三章:Java框架3.1 Spring框架3.1.1 Spring框架概述3.1.2 依赖注入3.1.3 AOP3.1.4 Spring MVC3.2 MyBatis框架3.2.1 MyBatis概述3.2.2 MyBatis配置3.2.3 MyBatis映射文件3.2.4 MyBatis动态SQL3.3 Spring Boot框架3.3.1 Spring Boot概述3.3.2 Spring Boot配置3.3.3 Spring Boot自动配置3.3.4 Spring Boot集成3.4 Spring Cloud框架3.4.1 Spring Cloud概述3.4.2 Spring Cloud配置3.4.3 Spring Cloud服务治理3.4.4 Spring Cloud分布式事务第四章:Java项目实战4.1 Java项目开发流程4.1.1 需求分析4.1.2 系统设计4.1.3 编码实现4.1.4 测试与部署4.2 Java项目案例4.2.1 基于Spring Boot的博客系统4.2.2 基于Spring Cloud的电商平台4.2.3 基于Java的在线教育平台4.2.4 基于Java的社交网络平台第五章:Java高级特性5.1 Lambda表达式5.1.1 Lambda表达式的基本语法5.1.2 Lambda表达式的应用场景5.1.3 Stream API5.2 Java NIO5.2.1 NIO概述5.2.2 文件IO操作5.2.3 缓冲区5.2.4 非阻塞IO5.3 Java内存模型5.3.1 内存区域5.3.2 垃圾回收5.3.3 内存泄漏5.4 Java并发编程5.4.1 线程池5.4.2 锁5.4.3 同步与并发工具类5.4.4 并发编程的艺术第六章:Java Web开发6.1 HTML与CSS6.1.1 HTML基本语法6.1.2 CSS样式表6.1.3 HTML5与CSS3新特性6.2 JavaScript基础6.2.1 JavaScript语法6.2.2 常用内置对象6.2.3 事件处理6.3 Java Web技术6.3.1 Servlet6.3.2 JSP6.3.3 EL表达式6.3.4 JSTL6.3.5 Filter和Listener 6.4 前端框架6.4.1 React6.4.2 Angular6.4.3 Vue.js第七章:Java安全与性能优化7.1 Java安全机制7.1.1 权限控制7.1.2 加密技术7.1.3 安全框架7.2 Java性能优化7.2.1 常见性能问题7.2.2 JVM调优7.2.3 代码优化7.2.4 数据库优化7.3 Java监控与日志7.3.1 监控工具7.3.2 日志框架7.3.3 日志管理第八章:Java项目实战案例8.1 企业级项目架构设计8.1.1 架构模式8.1.2 微服务架构8.1.3 分布式架构8.2 实战案例一:在线购物平台8.2.1 需求分析8.2.2 系统设计8.2.3 技术选型8.2.4 项目实施8.3 实战案例二:企业资源规划(ERP)系统8.3.1 需求分析8.3.2 系统设计8.3.3 技术选型8.3.4 项目实施8.4 实战案例三:银行系统8.4.1 需求分析8.4.2 系统设计8.4.3 技术选型8.4.4 项目实施第九章:Java EE技术9.1 Java EE概述9.2 Java EE核心技术9.2.1 EJB9.2.2 JPA9.2.3 JSF9.2.4 JMS9.2.5 Java EE安全性9.3 Java EE项目案例9.3.1 企业信息管理系统9.3.2 电子商务平台9.3.3 人力资源管理系统第十章:Java开发工具与环境10.1 Java开发工具10.1.1 IntelliJ IDEA 10.1.2 Eclipse10.1.3 NetBeans10.2 构建工具10.2.1 Maven10.2.2 Gradle10.3 版本控制10.3.1 Git10.3.2 SVN10.4 调试工具10.4.1 JDBCTrace10.4.2 JProfiler10.4.3 VisualVM第十一章:Java面试题11.1 Java基础面试题11.1.1 Java内存模型11.1.2 Java集合框架11.1.3 Java多线程11.1.4 Java异常处理11.2 Java Web面试题11.2.1 Servlet生命周期11.2.2 JSP原理11.2.3 JavaScript面试题11.3 数据库面试题11.3.1 JDBC11.3.2 MySQL11.3.3 Oracle11.4 Java框架面试题11.4.1 Spring框架11.4.2 MyBatis框架11.4.3 Spring Boot框架第十二章:Java技术前沿12.1 Java 9新特性12.1.1 模块化系统12.1.2 流式API12.1.3 JShell12.2 Java 10新特性12.2.1 LocalVariable Type Inference12.2.2 ZGC12.2.3 HTTP/212.3 Java 11新特性12.3.1 JEP 321: Dynamic ClassFile Constants 12.3.2 JEP 322: ForeignMemory Access API 12.3.3 JEP 323: HTTP/2 Client12.4 Java未来发展趋势12.4.1 云计算12.4.2 微服务12.4.3 容器化技术第十三章:Java性能调优13.1 JVM性能调优13.1.1 JVM参数优化13.1.2 垃圾收集器选择13.1.3 内存泄漏检测13.2 代码性能调优13.2.1 数据结构选择13.2.2 算法优化13.2.3 循环优化13.3 网络性能调优13.3.1 网络延迟优化13.3.2 网络吞吐量优化13.3.3 网络安全优化第十四章:Java安全编程14.1 Java安全机制14.1.1 访问控制14.1.2 权限管理14.1.3 安全认证14.2 加密技术14.2.1 对称加密14.2.2 非对称加密14.2.3 哈希算法14.3 安全框架14.3.1 Spring Security14.3.2 Apache Shiro14.3.3 Java Cryptography Architecture (JCA)第十五章:Java并发编程高级15.1 并发工具类15.1.1 CountDownLatch15.1.2 CyclicBarrier15.1.3 Semaphore15.1.4 Exchanger15.2 并发编程模型15.2.1 生产者消费者模型15.2.2 管道模型15.2.3 线程池模型15.3 并发编程的艺术15.3.1 锁的优化15.3.2 死锁的避免15.3.3 线程安全的集合第十六章:Java分布式系统16.1 分布式系统概述16.1.1 分布式计算16.1.2 分布式存储16.1.3 分布式事务16.2 分布式技术16.2.1 ZooKeeper16.2.2 Kafka16.2.3 Redis16.2.4 Dubbo16.3 分布式系统设计16.3.1 负载均衡16.3.2 服务发现16.3.3 数据同步第十七章:Java大数据技术17.1 Hadoop生态圈17.1.1 Hadoop概述17.1.2 HDFS17.1.3 MapReduce17.1.4 YARN17.2 Spark17.2.1 Spark概述17.2.2 Spark Core17.2.3 Spark SQL17.2.4 Spark Streaming 17.3 Flink17.3.1 Flink概述17.3.2 Flink流处理17.3.3 Flink批处理18.1 机器学习基础18.1.1 线性回归18.1.2 逻辑回归18.1.3 决策树18.1.4 支持向量机18.2 深度学习18.2.1 神经网络18.2.2 卷积神经网络18.2.3 循环神经网络18.3 Java深度学习框架18.3.1 Deeplearning4j 18.3.2 TensorFlow 18.3.3 PyTorch答案第一章:Java基础1.1 Java语言概述Java语言的起源Java语言的特点Java语言的运行环境 Java语言的开发工具1.2 Java语法基础数据类型变量和常量运算符控制语句1.3 面向对象编程类和对象构造方法继承多态封装1.4 异常处理异常的概念异常的捕获与处理自定义异常1.5 Java集合框架List接口Set接口Map接口Collection类Iterator接口Collection框架的常用类第二章:Java进阶2.1 Java多线程线程的概念线程的创建与运行线程同步线程通信2.2 Java网络编程URL类Socket编程HTTP协议2.3 Java数据库编程 JDBC概述JDBC连接数据库JDBC查询与更新JDBC事务管理2.4 Java设计模式单例模式工厂模式代理模式装饰者模式策略模式第三章:Java框架3.1 Spring框架Spring框架概述依赖注入AOPSpring MVC3.2 MyBatis框架MyBatis概述MyBatis配置MyBatis映射文件MyBatis动态SQL3.3 Spring Boot框架Spring Boot概述Spring Boot配置Spring Boot自动配置Spring Boot集成3.4 Spring Cloud框架Spring Cloud概述Spring Cloud配置Spring Cloud服务治理Spring Cloud分布式事务第四章:Java项目实战4.1 Java项目开发流程需求分析系统设计编码实现测试与部署4.2 Java项目案例基于Spring Boot的博客系统基于Spring Cloud的电商平台基于Java的在线教育平台基于Java的社交网络平台第五章:Java高级特性5.1 Lambda表达式Lambda表达式的基本语法Lambda表达式的应用场景Stream API5.2 Java NIONIO概述文件IO操作缓冲区非阻塞IO5.3 Java内存模型内存区域垃圾回收内存泄漏5.4 Java并发编程线程池锁同步与并发工具类并发编程的艺术第六章:Java Web开发6.1 HTML与CSSHTML基本语法CSS样式表HTML5与CSS3新特性6.2 JavaScript基础 JavaScript语法常用内置对象事件处理6.3 Java Web技术ServletJSPEL表达式JSTLFilter和Listener6.4 前端框架ReactAngularVue.js第七章:Java安全与性能优化7.1 Java安全机制权限控制加密技术安全框架7.2 Java性能优化常见性能问题JVM调优代码优化数据库优化7.3 Java监控与日志监控工具日志框架日志管理第八章:Java项目实战案例8.1 企业级项目架构设计架构模式微服务架构分布式架构8.2 实战案例一:在线购物平台需求分析系统设计技术选型项目实施8.3 实战案例二:企业资源规划(ERP)系统需求分析系统设计技术选型项目实施8.4 实战案例三:银行系统需求分析系统设计技术选型项目实施第九章:Java EE技术9.1 Java EE概述Java EE核心技术EJBJPAJSFJMSJava EE安全性9.2 Java EE项目案例企业信息管理系统电子商务平台人力资源管理系统第十章:Java开发工具与环境10.1 Java开发工具。
Java第四章课后习题解答:1.//filename: App4_1.javaimport java.io.*;public class App4_1{public static void main(String[] args)throws IOException{ float score;String str;BufferedReader buf=new BufferedReader(new InputStreamReader (System.in));System.out.println("请你输入一个成绩: ");str=buf.readLine();score=Float.parseFloat(str);int grade=(int)score/10;switch(grade){case 10:case 9: System.out.println(" 优");break;case 8: System.out.println(" 良");break;case 7: System.out.println(" 中");break;case 6: System.out.println(" 及格");break;default: System.out.println(" 不及格");}}}2.//filename: App4_2.javaimport java.io.*;public class App4_2{public static void main(String[] args){int score;int grade;char result;Scanner b = new Scanner(System.in);score = b.nextInt();grade = score / 10;switch(grade)case 10:case 9:case 8: result = 'A';break;case 7: result = 'B';break;case 6: result = 'C';break;default: result = 'D';break;}System.out.println(result);}}3.//filename: App4_3.javapublic class App4_3{public static void main(String[] args) {int i;for( i=1;i<=100;i++){if(i%3==0 && i%7==0)System.out.println("i="+i);}}}4.//filename: App4_4.javapublic class App4_4{public static void main(String[] args) {int i,n;int s=0;for(i=1,i<=n,i++)n=i*n;s=s+n;System.out.println("s="+s);}}//filename: App4_5.javaimport java.util.*;public class App4_5{public static void main(String arg[]){Scanner insert=new Scanner(System.in);int n;System.out.print("请输入一个数字n:");n = insert.nextInt();double b=1;double e=1;double f=1;double g= (-1);double sum=0;for (int i=1; i <= n ; i++ ){e=e*i;b=( 1 / e );g = g*(-1);f=b*g;sum=sum+f;}System.out.println("sum=1!-(1/2!)+(1/3!)-(1/4!)+......-((-1)^(n-1))*(1/n!)="+sum); }}6.//filename: App4_6.javapublic class App4_6{public static void main(String[] args){for(int i=100; i<1000; i++){int gw = i%10;int sw = i/10%10;int bw = i/100;int gl=g*g*g;int sl=s*s*s;int bl=b*b*b;int s = gl+sl+bl;boolean eq = s==i;if(eq)System.out.println(i+"="+bw+"^3+"+sw+"^3+"+gw+"^3"); }}}}7.//filename: App4_7.javaimport java.util.*;public class App4_7{public static void main(String[] args){int x,s=0;System.out.print("请输入你需要的整数:");Scanner scan=new Scanner(System.in);x=scan.nextInt();for(int i=1;i<x;i++){if(x%i==0){s=s+i;}els{continue;}}if(s==x){System.out.println(x+"是完全数");}else{System.out.println(x+"不是完全数");}}}8.//filename: App4_8.javaimport java.util.*;public class App4_8{public static void main(String[] args){String n;int d,x;int m,end=0,sum=0;System.out.print("请输入一个数:");Scanner scan=new Scanner(System.in);n=scan.nextLine();d=n.length();x=Integer.parseInt(n);for (int i=1; i<=d;i++ ){m=x%10;x=x/10;end=end+m;}System.out.println(end);}}9.//filename: App4_9.javaimport java.util.*; public class App4_9 {public static void main(String arg[]){Scanner insert=new Scanner(System.in);float i;int j;float k;System.out.print("输入一个浮点型数字:");i = insert.nextFloat();j = (int)i;k = i-j;System.out.println("输入的数字的整数部分:"+j);System.out.println("输入的数字的小数部分:"+k);}}10.//filename: App4_10.javapublic class App4_10{public static void main(String arg[]){double x=3000;int y=0;while (x >= 5 ){x *= 0.5;y += 1;}System.out.println("需要"+y+"天,绳子的长度会短于米"); }}11.//filename: App4_11.javapublic class App4_11{public static void main(String arg[]){int q;int h = 1;for (int i= -1 ; i <= 4 ; i++ ){h = h + i;q = h;System.out.println();for (int j=i+2 ; j <= 5 ; j++ ){System.out.print((q=q+j)+"\t");}}}}。
第四章1. 关于内部类,下列说法不正确的是()。
内部类不能有自己的成员方法和成员变量2. 有一个类B,下面为其构造方法的声明,正确的是()。
B(int x) {}3. 为AB类定义一个无返回值的方法f,使得使用类名就可以访问该方法,该方法头的形式为()static void f()4. 在Java语言中,哪一个包中的类是自动导入的?()ng5. 定义外部类时不能用到的关键字是()。
protected6. 下列哪种类成员修饰符修饰的变量只能在本类中被访问?()private7. 定义一个公有double型常量PI,哪一条语句最好?()public final static double PI=3.14;8. 下面关于方法的说法,不正确的是()。
如果一个类定义了构造方法,也可以用该类的默认构造方法9. 下面关于类的说法,不正确的是()。
类就是对象10. 给出下面的程序代码:public class X4_1_3 {private float a;public static void m ( ){ }}如何使成员变量a被方法m( )访问()将private float a改为static float a11. 给出下面程序代码:byte[] a1, a2[];byte a3[][];byte[][] a4;下列数组操作语句中哪一个是不正确的?()a2 = a112. 下面代码运行后的输出结果为()。
public class X6_1_5 {public static void main(String[] args) {AB aa = new AB();AB bb;bb = aa;System.out.println(bb.equals(aa));}}class AB{ int x = 100; }true13. 设有下列数组定义语句:int a[] = {1, 2, 3};则对此语句的叙述错误的是()。
JavaSE习题第四章类与对象问答题:
1.在声明类时,类名应该遵守哪些习惯? 1.与⽂件名相同2.⾸字母⼤写2.类体内容中有那两类⽐较重要的成员? 1.成员变量2.⽅法3.实例⽅法可以操作类变量吗?类⽅法可以操作实例变量吗? 类中的实例⽅法可以操作类变量因为类总是先于实例存在的 实例只是类在特定状态下的⼀个特定对象 所以必须类存在 才能从类创建实例 所以实例⽅法可以操作类变量 因为类变量肯定存在 类⽅法不可以操作实例变量因为类⽅法的作⽤域在类上 类本⾝并不知道⾃⼰被创建了多少实例 这些实例哪些还存在 所以类⽅法没有办法访问到实例变量
4.当类的字节码加载到内存时,类变量⼀定分配了内存空间吗? 是的5.类的实例变量在什么时候分配内存空间? new的时候6.⼀个类的类变量被该类创建的所有对象共享吗? 是的7.不同对象的实例变量分配的内存空间地址⼀定不同嘛? 不⼀定8.上⾯叫⽅法的重载?构造⽅法可以重载嘛? 重载(overload),⽅法名⼀样,但是返回类型或者传参不⼀样。构造⽅法也可以重载。9.为什么类⽅法不可以调⽤实例⽅法。 实例⽅法没有加载进内存,必须以new的⽅式加载10.为什么类⽅法不能操作实例成员变量? 没加载进内存,理由和上⼀题⼀样11.实例⽅法可以⽤类名直接调⽤吗? 不⾏,先new出来12.关键字this可以出现在构造⽅法中?可以出现在实例⽅法中?可以出现在类⽅法中? 都⾏13.源⽂件声明编写的类⼀定在同⼀包中嘛? 不⼀定,可以导包14.“import java.awt.*;”和"import java.awt.Button"有什么不同? 前⼀个内存加载awt下所有类,第⼆个只加载button15.程序中如果使⽤了“import java.util.*;”;程序运⾏时,要加载java.util包中全部类到内存嘛? 要的16.有哪⼏种访问权限修饰符,说出作⽤。 public 所有地⽅均能访问该类 private 除本类都不能访问 protected 除本类,本包和⼦类(其他包下⼦类也⾏),其他包下都不能访问 不加(Default) 除了本类,本包,⼦类和其他类都不能访问17.怎么反编译⼀个类 使⽤java⾃带的javap18.请写出下列代码中类A的输出结果(题⽬少数据)作业题1.编写⼀个类,该类创建对象可以计算等差数列的和。
PDF上的实验4.1 对象的创建和使用4.1 Rectangle是一个矩形类,该类包含两个成员变量width和length分别表示矩形的宽和长。
成员方法area()用来计算矩形的面积。
试填写下列程序中的空白部分,以输出一个宽为2.5长为8.7的举行的面积。
(提示:应首先填写Rectangle的构造函数)。
class JLab0401{public static void main(String[] args){Rectangle myRect = new Rectangle(2.5,8.7);double theArea;theArea = myRect.area();System.out.println("My rectangle has area " + theArea);}} //end of class JLab0401class Rectangle{double width, length;Rectangle(double widthd,double lengthd){width=widthd;length=lengthd;}public double area(){double a;a = length * width;return a;}} //end of class Rectangle2.编译并执行你填写完整的程序(3)在上述程序的JLab0401类中main方法中添加相关语句,使之能够输出矩形的长和宽的值。
编译并执行该程序,以验证你更改的正确性。
class JLab0401{public static void main(String[] args){Rectangle myRect = new Rectangle(2.5,8.7);double theArea;theArea = myRect.area();System.out.println("My rectangle's length " + myRect.length); System.out.println("My rectangle's width " + myRect.width);System.out.println("My rectangle has area " + theArea);}} //end of class JLab0401class Rectangle{double width, length;Rectangle(double widthd,double lengthd){width=widthd;length=lengthd;}public double area(){double a;a = length * width;return a;}} //end of class Rectangle黑体是添加的语句,其运行结果是:(4)在(3)成功的基础上,在Rectangle类中添加公共方法setWidth和setLength 方法,这两个方法分别用来设置矩形的长宽值。
1、
已知类的定义如下
public class test_3{
int x ;
int y ;
test_3(int a,int b){
x=a;
y=b;
}
test_3(){
x=-1;
y=-1;
}
int get_x()
{
return x++;
}
int get_y()
{
return y--;
}
如果用下面三种不同的方法加载类,写出要求的结果:
(1)用test_3 a1=new test_3()后;a1.x的内容为_____ ,a1.y的内容为______。
(2) 用test_3 a1=new test_3(-2,5)后;a1.x的内容为_____ ,a1.y的内容为______。
(3)用test_3 a1=new test_3(10)后;其结果是__________。
2、 设 int x=1,float y=2,则表达式 x / y的值是( )
A、0 B、1 C、2 D、以上都不是
3、以下语句有语法错的是( )
A、int x=1;y=2;z=3 B、for (int x=10,y=0;x>0;x++);
C、while (x>5); D、for(; ;);
4、void 的含义( )
A、方法体为空 B、定义的方法没有形参
C、定义的方法没有返回值 D、方法的返回值不能参加算术运算
5、以下有关类定义的说法正确的是( )
A、一个类可以有成员,也可以没有成员 B、类的成员至少有一个属性和一个方法
C、类的静态属性同全局变量的概念完全一样,只是表达形式不同
D、类的方法在实例化时不占用内存
6、以下有关构造函数的说法,正确的是( )
A、一个类的构造函数可以有多个 B、构造函数在类定义时被调用
C、构造函数只能由对象中的其它方法调用。
D、构造函数可以和类同名,也可以和类名不同
7、以下有关类的继承的说明中,正确的是( )
A、子类能直接继承父类所有的非私有属性,也可通过接口继承父类的私有属性
B、子类只能继承父类的方法,不能继承父类的属性
C、子类只能继承父类的非私有属性,不能继承父类的方法
D、子类不能继承父类的私有属性
8、以下有关类的构造函数继承的说明,正确的是( )
A、子类继承父类的构造函数,但不能自己定义
B、子类可定义自己的构造函数,但受父类定义的构造函数的限制
C、子类和父类均可独自定义自己的构造函数,但执行时的顺序有规定
D、如父类定义了构造函数,则子类只能继承父类的构造函数,不能自己定义
9、this 和super的使用中,正确的是( )
A、都是指一个内存地址 B、可以在同一个方法定义中出现
C、 意义相同 D、以上都不
10、分析以下程序,下面(AC)方法是对setVar方法的重载。
public class MethodOver{
public void setVar(int a,int b,float c){}
}
a) private void setVar(int a,float c,int b){}
b) protected void setVar(int a,int b,float c){}
c) public int setVar(int a,float c,int b){return a;}
d) public int setVar(int a,int b,float c){return b;}
e) protected float setVar(int a,int b,float c){return c;}
11、以下程序的运行结果是()
public class Example{
String str=new String(“good”);
char[ ] ch={‘a’,’b’,’c’};
public static void main(String args[]){
Example ex=new Example();
ex.change(ex.str,ex.ch);
System.out.print(ex.str+” and “);
System.out.print(ex.ch);
}
public void change(String str,char ch[]){
str=”test ok”;
ch[0]=’g’;
}
}
f) good and abc
g) good and gbc
h) test ok and abc
i) test ok and gbc
12、下面()情况属于“is a”的关系
j) public interface Color{}
public class Shape{
private Color color;
}
k) interface Component{}
class Container implements Component{
private Component[] children;
}
l) public class Species{}
public class Animal{
private Species species;
}
m) public class Species{
private Animal ananimal;
}
public class Animal{}
13、设有下面的两个类定义:
class AA {
void Show(){ System.out.println(“我喜欢Java!”);
}
class BB extends AA {
void Show(){ System.out.println(“我喜欢C++!”);
}
则顺序执行如下语句后输出结果为:( )
AA a; BB b;
a.Show(); b.Show();
A、我喜欢Java! B、我喜欢C++!
我喜欢C++! 我喜欢Java!
C、我喜欢Java! D、我喜欢C++!
我喜欢Java! 我喜欢C++!
14、在Java中,一个类可同时定义许多同名的方法,这些方法的形式参数的个数、类型或
顺序各不相同,传回的值也可以不相同。这种面向对象程序特性称为( )。
A、继承 B、构造 C、重载 D、重写
15、对于构造函数,下列叙述正确的是( )。
A、构造函数也允许重载。
B、子类无条件地继承父类的无参构造函数。
C、子类不允许调用父类的构造函数。
D、在同一个类中定义的重载构造函数可以相互调用。