OCP Java17 SE Developers 复习题04

news2024/11/14 21:36:25

======================答案=========================

F.  Line 5 does not compile. This question is checking to see whether you are paying attention to the types. numFish is an int, and 1 is an int. Therefore, we use numeric addition and get 5. The problem is that we can't store an int in a String variable. Suppose line 5 said String anotherFish = numFish + 1 + "";. In that case, the answers would be option A and option C. The variable defined on line 5 would be the string "5", and both output statements would use concatenation.

======================答案=========================

C, E, F.  Option C uses the variable name as if it were a type, which is clearly illegal. Options E and F don't specify any size. Although it is legal to leave out the size for later dimensions of a multidimensional array, the first one is required. Option A declares a legal 2D array. Option B declares a legal 3D array. Option D declares a legal 2D array. Remember that it is normal to see classes on the exam you might not have learned. You aren't expected to know anything about them.

======================答案=========================

A, C, D.  Option B throws an exception because there is no March 40. Option E also throws an exception because 2023 isn't a leap year and therefore has no February 29. Option F doesn't compile because the enum should be named Month, rather than MonthEnum. Option D is correct because it is just a regular date and has nothing to do with daylight saving time. Options A and C are correct because Java is smart enough to adjust for daylight saving time.

======================答案=========================

A, C, D.  The code compiles fine. Line 3 points to the String in the string pool. Line 4 calls the String constructor explicitly and is therefore a different object than s. Line 5 checks for object equality, which is true, and so it prints one. Line 6 uses object reference equality, which is not true since we have different objects. Line 7 calls intern(), which returns the value from the string pool and is therefore the same reference as s. Line 8 also compares references but is true since both references point to the object from the string pool. Finally, line 9 is a trick. The string Hello is already in the string pool, so calling intern() does not change anything. The reference t is a different object, so the result is still false.

======================答案=========================

B.  This example uses method chaining. After the call to append()sb contains "aaa". That result is passed to the first insert() call, which inserts at index 1. At this point, sb contains abbaa. That result is passed to the final insert(), which inserts at index 4, resulting in abbaccca.

======================答案=========================

C.  Remember to watch return types on math operations. One of the tricks is line 24. The round() method returns an int when called with a float. However, we are calling it with a double, so it returns a long. The other trick is line 25. The random() method returns a double. Since two lines have a compiler error, option C is the answer.

======================答案=========================

A, E.  When dealing with time zones, it is best to convert to GMT first by subtracting the time zone. Remember that subtracting a negative is like adding. The first date/time is 9:00 GMT, and the second is 15:00 GMT. Therefore, the first one is earlier by six hours.

======================答案=========================

A, B, F.  Remember that indexes are zero-based, which means index 4 corresponds to 5, and option A is correct. For option B, the replace() method starts the replacement at index 2 and ends before index 4. This means two characters are replaced, and charAt(3) is called on the intermediate value of 1265. The character at index 3 is 5, making option B correct. Option C is similar, making the intermediate value 126 and returning 6.

Option D results in an exception since there is no character at index 5. Option E is incorrect. It does not compile because the parentheses for the length() method are missing. Finally, option F's replace results in the intermediate value 145. The character at index 2 is 5, so option F is correct.

======================答案=========================

A, C, F.  Arrays are zero-indexed, making option A correct and option B incorrect. They are not able to change size, which is option C. The values can be changed, making option D incorrect. An array does not override equals(), so it uses object equality. Since two different objects are not equal, option F is correct, and options E and G are incorrect.

======================答案=========================

A.  All of these lines compile. The min() and floor() methods return the same type passed in: int and double, respectively. The round() method returns a long when called with a double. Option A is correct since the code compiles.

======================答案=========================

E.  A LocalDate does not have a time element. Therefore, there is no method to add hours, making option E the answer.

======================答案=========================

A, D, E.  First, notice that the indent() call adds a blank space to the beginning of numbers, and stripLeading() immediately removes it. Therefore, these methods cancel each other out and have no effect. The substring() method has two forms. The first takes the index to start with and the index to stop immediately before. The second takes just the index to start with and goes to the end of the String. Remember that indexes are zero-based. The first call starts at index 1 and ends with index 2 since it needs to stop before index 3. This gives us option A. The second call starts at index 7 and ends in the same place, resulting in an empty String which is option E. This prints out a blank line. The final call starts at index 7 and goes to the end of the String finishing up with option D.

======================答案=========================

B.  A String is immutable. Calling concat() returns a new String but does not change the original. A StringBuilder is mutable. Calling append() adds characters to the existing character sequence along with returning a reference to the same object. Therefore, option B is correct.

======================答案=========================

A, F.  Option A correctly creates the current instant. Option F is also a proper conversion. Option B is incorrect because Instant, like many other date/time classes, does not have a public constructor and is instantiated via methods. Options C, D, and E are incorrect because the source object does not represent a point in time. Without a time zone, Java doesn't know what moment in time to use for the Instant.

======================答案=========================

C, E.  Numbers sort before letters and uppercase sorts before lowercase. This makes option C one of the answers. The binarySearch() method looks at where a value would be inserted, which is before the second element for Pippa. It then negates it and subtracts one, which is option E.

======================答案=========================

A, B, G.  There are 11 characters in base because there are two escape characters. The \n counts as one character representing a new line, and the \\ counts as one character representing a backslash. This makes option B one of the answers. The indent() method adds two characters to the beginning of each of the two lines of base. This gives us four additional characters. However, the method also normalizes by adding a new line to the end if it is missing. The extra character means we add five characters to the existing 11, which is option G. Finally, the translateEscapes() method turns any text escape characters into actual escape characters, making \\t into \t. This gets rid of one character, leaving us with 10 characters matching option A.

======================答案=========================

A, G.  The substring() method includes the starting index but not the ending index. When called with 1 and 2, it returns a single-character String, making option A correct and option E incorrect. Calling substring() with 2 as both parameters is legal. It returns an empty String, making options B and F incorrect. Java does not allow the indexes to be specified in reverse order. Option G is correct because it throws a StringIndexOutOfBoundsException. Finally, option H is incorrect because it returns an empty String.

======================答案=========================

C, F.  This question is tricky because it has several parts. First, you have to know that the text block on lines 13 and 14 is equivalent to a regular String. Since there is no line break at the end, this is four characters. Then, you have to know that String objects are immutable, which means the results of lines 17–19 are ignored. Finally, on line 20, something happens. We concatenate three new characters to s1 and now have a String of length 7, making option C correct.

======================答案=========================

A, B, D.  The compare() method returns a positive integer when the arrays are different and the first is larger. This is the case for option A since the element at index 1 comes first alphabetically. It is not the case for option C because the s4 is longer or for option E because the arrays are the same.

The mismatch() method returns a positive integer when the arrays are different in a position index 1 or greater. This is the case for options B and D since the difference is at index 1. It is not the case for option F because there is no difference.

======================答案=========================

A, D.  The dateTime1 object has a time of 1:30 per initialization. The dateTime2 object is an hour later. However, there is no 2:30 when springing ahead, setting the time to 3:30. Option A is correct because it is an hour later. Option D is also correct because the hour of the new time is 3. Option E is not correct because we have changed the time zone offset due to daylight saving time.

======================答案=========================

A, C.  The reverse() method is the easiest way of reversing the characters in a StringBuilder; therefore, option A is correct. In option B, substring() returns a String, which is not stored anywhere. Option C uses method chaining. First, it creates the value "JavavaJ$". Then, it removes the first three characters, resulting in "avaJ$". Finally, it removes the last character, resulting in "avaJ". Option D throws an exception because you cannot delete the character after the last index. Remember that deleteCharAt() uses indexes that are zero-based, and length() counts the number of characters rather than the index.

======================答案=========================

A.  The date starts out as April 30, 2022. Since dates are immutable and the plus methods' return values are ignored, the result is unchanged. Therefore, option A is correct.

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1079343.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

新媒体达人投放技巧有哪些,投放总结!

达人投放,一个当今时代品牌传播跳不开的词。关于达人投放的优势与特点,相信所有人都已经不在陌生。但是真的进行达人投放时,又该如何实施,今天来分享下新媒体达人投放技巧有哪些,投放总结! 一、品牌不同阶段…

Redis分布式系统: 主从复制

“你小心保管我,不思议的念头。秘密从不会对谁泄漏~” 什么是分布式系统? 分布式系统的出现,就是为了解决单机问题(硬件资源不足)。在分布式系统中,通常会把数据复制多个副本部署到其他服务器,满⾜故障恢复和负载均衡等…

通讯网关软件020——利用CommGate X2Mysql实现Modbus TCP数据转储Mysql

本文介绍利用CommGate X2MYSQL实现从Modbus TCP设备读取数据并转储至MYSQL数据库。CommGate X2MYSQL是宁波科安网信开发的网关软件,软件可以登录到网信智汇(http://wangxinzhihui.com)下载。 【案例】如下图所示,实现从Modbus TCP设备读取数据并转储至M…

苹果ios安卓apk应用APP文件怎么修改手机APP显示的名称

修改应用名称虽然很简单,但是也是由很多喜欢代码却不是很懂代码的白白同学,所以在这里我简单的说一下具体的话还是要靠同学们自行研究,由更好的方式也可以评论区说一下哈,让俺们也学习学习。 要修改 APK 文件的应用名称&#xff…

【rust基础】基本类型、所有权与借用、复合类型

文章目录 1 基本类型1.1 数值类型1.1.1 Rust 中的内置的整数类型:1.1.2 浮点类型1.1.3 数学运算1.1.4 位运算1.1.5 序列(Range) 1.2 字符、布尔、单元类型1.3 语句和表达式1.4 函数 2 所有权与借用2.1 栈(Stack)与堆(Heap)2.2 所有权原则2.2.1 转移所有权2.2.2 克隆…

VMware安装CentOS虚拟机

1. 简介 VMware 虚拟机是一种基于虚拟化技术的软件应用程序,它允许用户在一台物理计算机上模拟多个虚拟计算环境。虚拟机提供了一个可隔离且独立于物理硬件的虚拟环境,其中可以安装和运行操作系统和应用程序。 官网地址:https://www.vmware…

IT运维管理平台助力企业打造监、管、控一体化

成立20多年业务遍及全球100多个国家和地区的某大型企业随着全球化业务快速发展,业务对信息系统运维的可用性和持续性要求随之越来越高,伴随业务发展带来的IT环境复杂度呈指数级增加,系统运维工作正面临严峻的挑战。在业务系统运行过程中&…

金融人为什么都在争先申请中国人民大学与加拿大女王大学金融硕士

“知识就是力量”,这是弗朗西斯培根的名言,也是金融行业人才追求的动力。2023年,随着金融行业的飞速发展和复杂性的增加,各企业对优秀人才的需求更加迫切。在这场激烈的人才争夺战中,越来越多的金融人选择了在职研究生…

【AI视野·今日Robot 机器人论文速览 第五十期】Mon, 9 Oct 2023

AI视野今日CS.Robotics 机器人学论文速览 Mon, 9 Oct 2023 Totally 25 papers 👉上期速览✈更多精彩请移步主页 Daily Robotics Papers Learning to Grasp: from Somewhere to Anywhere Authors Fran ois H l non, Johann Huber, Fa z Ben Amar, St phane Doncieux…

基于大规模分布式系统的云原生运维实践

在云计算、大数据、人工智能等新兴技术的推动下,众多行业都在经历一场轰轰烈烈的数字化转型大潮。随着容器技术和编排系统的发展、基础设施不断云化、分布式微服务架构不断演进和敏捷、DevOps等开发理念的带动,应用云化已经是不可逆转的趋势,云原生也成为…

uni-app:实现简易自定义下拉列表

效果 代码 <template><view><view class"dropdown-trigger" tap"showDropdown">{{ selectedItem }}</view><view class"dropdown-list" v-if"showList"><view class"dropdown-item" v-f…

【面试题精讲】finally 中的代码一定会执行吗?

文章目录 finally 块的作用finally 中的代码一定会执行吗&#xff1f;1. System.exit() 导致 JVM 终止2. 无限循环或死锁3. 程序被强制终止 示例代码演示示例 1&#xff1a;正常情况下执行 finally 块示例 2&#xff1a;发生异常时执行 finally 块示例 3&#xff1a;System.exi…

ACL访问控制列表的解析和配置

ACL的解析 个人简介 ACL - Access Control List 访问控制列表 策略 ------行为 允许/拒绝 ACL --包含两种 标准ACL 扩展ACL 标准ACL&#xff1a;只能针对源IP地址做限制 针对路由条目的限制 -路由策略 思科编号&#xff1a;1-99之间或1300-1999 扩展ACL&#xff1a;针对…

SLAM从入门到精通(3d 点云数据访问)

【 声明&#xff1a;版权所有&#xff0c;欢迎转载&#xff0c;请勿用于商业用途。 联系信箱&#xff1a;feixiaoxing 163.com】 3d 点云设备现在汽车上用的很多。之前3d lidar这种高端传感器&#xff0c;只能被少部分智能汽车使用。后来很多国产厂家也开始研发3d lidar之后&am…

从0开始微信小程序开发

项目构成 小程序页面组成部分 WXML模板 WXML和HTML的区别 分别对应的是布局&#xff0c;文本&#xff0c;图像&#xff0c;导航跳转 WXSS 用来美化页面结构 view默认占满一行

数据治理的核心是什么?_光点科技

数据治理是当今数字化时代中企业管理的关键组成部分。在信息爆炸的时代&#xff0c;企业积累了大量的数据&#xff0c;这些数据不仅是企业宝贵的资产&#xff0c;也是推动业务决策和创新的重要驱动力。数据治理的核心在于建立有效的框架和流程&#xff0c;以确保数据的质量、安…

计算机竞赛 题目:基于深度学习的图像风格迁移 - [ 卷积神经网络 机器视觉 ]

文章目录 0 简介1 VGG网络2 风格迁移3 内容损失4 风格损失5 主代码实现6 迁移模型实现7 效果展示8 最后 0 简介 &#x1f525; 优质竞赛项目系列&#xff0c;今天要分享的是 基于深度学习卷积神经网络的花卉识别 该项目较为新颖&#xff0c;适合作为竞赛课题方向&#xff0c…

基于ChatGPT+词向量/词嵌入实现相似商品推荐

最近一个项目有个业务场景是相似商品推荐&#xff0c;给一个商品描述(比如 WIENER A/B 7IN 5/LB FZN )&#xff0c;系统给出商品库中最相似的TOP 5种商品&#xff0c;这种单纯的推荐系统用词向量就可以实现&#xff0c;不过&#xff0c;这个项目特点是商品库巨大&#xff0c;有…

Docker与Serverless计算的集成: Docker容器如何与Serverless计算结合。

文章目录 1. Docker容器的可移植性2. Serverless计算的自动伸缩性3. 使用Serverless与Docker容器a. 自托管Serverless平台b. 使用容器服务 4. 使用案例&#xff1a;图像处理服务5. 结论 &#x1f388;个人主页&#xff1a;程序员 小侯 &#x1f390;CSDN新晋作者 &#x1f389;…

MPP 架构在 OLAP 数据库的运用

MPP 架构&#xff1a; MPP 架构的产品&#xff1a; Impala ClickHouse Druid Doris 很多 OLAP 引擎都采用了 MPP 架构 批处理系统 - 使用场景分钟级、小时级以上的任务&#xff0c;目前很多大型互联网公司都大规模运行这样的系统&#xff0c;稳定可靠&#xff0c;低成本。…