版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、Multiple ChoiceIWhich operator is used to con cate nate two stri ngs?(a+(b-(c*(d/An swer:A(see page352Which operator returns the rema in der of in teger divisio n?(a%(b/ (c* (dnone of the aboveAn swer:A(see page263What is the value of the variable c in the statements that follow?Stri ng phrase="
2、;Make hay while the sun is shi nin g." char c=phrase.charAt(10;(aw(bh (ci(dNone of the aboveAn swer:B(see page404The escape seque nee the represe nts the n ew-l ine character is:(ar(bt(c n(dAn swer:C(see page435The syn tax that declares a Java n amed con sta nt n amed SALES_TAX is:(adouble SALE
3、S_TAX=7.50;(bpublic double SALES_TAX=7.50;(cpublic static double SALES_TAX=7.50;(dpublic static final double SALES_TAX=7.50;An swer:D(see page476ln Java,a block comme nt is delimited by:(a*/*(b/*/*(c/*/(d*/*/An swer:C(see page507To mark a block comme nt for in clusi on in the Javadoc docume ntatio n
4、,the block mustbe delimited by:(a/*/(b*/*/(c*(d*/*/An swer:A(see page508Valid arguments to the System.out oject ' s printin method include:(a “Anything with double quotes”(bStri ng variables(cVariables of type int(dAll of the aboveAn swer:D(see page599Which stateme nt or group of stateme nts pro
5、duces the output:Java program ming isfun!(aSystem.out.pri nt(Java program ming;System.out.pri nt(is fun!;(bSystem.out.println(Java programming is fun!;(cSystem.out.pri ntl n(Java program ming;System.out.pri ntl n(“ is fun! ”;(dSystem.out.pri nt(Java program mingSystem.out.pri ntl n(“ is fun! ”;An sw
6、er:D(see page6010If a hyphen is added after the%in a format specifier,the output will be(aLeft justified(bRight justified(cCe ntered(dNone of the aboveAn swer:A(see page6411The statement:System.out.printf("%6.2f",597.7231;displays:(a597.723(b597.72(C000597.72(dNone of the aboveAn swer:B(se
7、e page6412The Java method printf is based on theIan guage.(aPascal(bC+(cC(dADAAn swer:C(see page6713The class NumberFormat allows you to specify a con sta nt represe nti ng which country ' scurre ncy format should be used.To use this con sta nt you must import:(ajava.util Locale(bjava.util.Curre
8、 ncy(cjava.util.Properties(dN one of the above.An swer:A(see page7114Sta ndard code libraries in Java are called:(aMethods(bClasses(cPackages(dStateme ntsAn swer:C(see page7215What Java package in eludes the class Scanner?(aawt(bsw ing(cio(dutilAn swer:D(see page78True/FalseObjects of type String ar
9、e strings of characters that are written within single quotes.An swer:False(see page342ln Java,Stri ngs are immutable objects .Im mutable objects can be cha nged.An swer:False(see page443An adva ntage of using the Uni code character set is that it easily han dles Ian guages other tha n En glish.An s
10、wer:True(see page444Java uses the ASCII character set.An swer:False(see page44lEfficie ncy is lost in importi ng the en tire package in stead of importi ng the classesyouuse.An swer:False(see page732Every Java program automatically imports the java.util package.An swer:False(see page733The newline c
11、haracter is represe nted asi'.An swer:True(see page614The method printf is used the same way as the method printin but has the added featurethat allows you to add formatting instructions.An swer:False(see page615The printf method can be used to output multiple formatted values.An swer:True(see p
12、age646The Scanner class has a method next that allows an entire line of string text to be read.An swer:False(see page807Echo ing in put is good program ming practice because it can reveal problems in thein put.An swer:True(see page80Short An swer/Essay1How is the%(modulusoperator used?What is the co
13、m mon use of the modulusoperator?An swer:The modulus operator is used to retur n the rema in der in in teger divisi on.For example,the modulus operator is commonly used to determine if a number is an eve n or an odd value.2What is the output of the followi ng Java stateme nts?/Stri ng method example
14、sString str="Java Programmi ng!"System.out.pri ntl n( str.equals("Java Program min g!"System.out.pri ntln( str.toLowerCase(;System.out.pri ntln( str.toUpperCase(;System.out.pri ntln( str.substri ng(5,8;System.out.pri ntln( str.last In dexOf("m"An swer:truejava program m
15、ing!JAVA PROGRAMMING!Pro123 Write a Java stateme nt to access the 7th character in the String variable myStri ng and place it in the char variable c. Answer: c = myString.charAt(6; 4 Write a Java stateme nt to determ ine the len gth of a string variable called in put. Store the result in an in teger
16、 variable called strLe ngth. An swer: int strLe ngth = in put.le ngth(; 5 Write ONE Java stateme nt to display your first and last n ame on two separate lin es. An swer: System.out.pri nt("WallynWon ders" 6 Write a complete Java con sole applicati on that prompts the user for two numbers,
17、multiplies the numbers, and then displays the result to the user. An swer: import java.util.Sca nner; public class Con soleMultiply public static void main( Stri ng args /Create the sca nner object for con sole in put Scanner keyboard =new Scanner(System.in; /Prompt the user for the first number Sys
18、tem.out.print("Enter the first in teger: " /Read the in put int firstNumber = keyboard .n extI nt(; /Prompt the user for the sec ond nu mber System.out.pri nt("E nter the sec ond in teger:"/Read the sec ond nu mber int sec on dNumber = keyboard .n extI nt(; System.out.pri ntln (f
19、irstNumber + "*" + sec on dNumber + " is " + firstNumber * sec on dNumber; 7 Write a Java stateme nt to create and in itialize a Scanner object n amed in put. An swer: Scanner in put = new Scann er(System.i n; 8 Con sider the followi ng code snippet. int i = 10; int n = i+%5; 1)
20、What are the values of i and n after the code is executed? An swer: i is 11, and n is 0. 2 What are the final values of i and n if in stead of using the postfix in creme nt operator (i+, you use the prefix versi on (+i? An swer: i is 11, and n is 1. 9 Program ming projects : questio n 2 and 3 (see p
21、age 93 import java.util.Scanner; public class Question2 public static void main(String args / Variable declarati ons Scanner scan = new Scann er(System.i n; Stri ng first; Stri ng last; System.out.pri ntl n("E nter your first n ame:" first = sca n.n extL in e(;System.out.pri ntln ("E
22、nter your last n ame:" last = sca n.n extL in e(; System.out.pri ntl n(first + " " + last + " turned to Pig Latin is:" / First convert first name to pig latinStri ng pigFirstName = first.substri ng(1,first.le ngth( + first.substri ng(0,1 + "ay" / Then capitalize fi
23、rst letter pigFirstName = pigFirstName.substring(0,1.toUpperCase( + pigFirstName.substring(1,pigFirstName.length(; / Repeat for the last name String pigLastName = last.substring(1,last.length( + last.substring(0,1 + "ay" / Then capitalize first letter pigLastName = pigLastName.substri ng(0,1.toUpperCase( + pigLastName.substri ng(1,pigLastName .len gth(; System.out.pri ntl n(
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 杜绝校园欺凌共建和谐校园演讲稿范文(3篇)
- 北京市海淀区2024-2025学年高二上学期9月月考 数学试题(含解析)
- DB12-T 1110-2021 企业开办登记规范
- 贡献社会主题班会教案
- 上海市市辖区(2024年-2025年小学五年级语文)统编版小升初模拟((上下)学期)试卷及答案
- 上海市县(2024年-2025年小学五年级语文)统编版专题练习(上学期)试卷及答案
- 浙江省台州市台州十校联考2024-2025学年高一上学期11月期中日语试题含答案
- 人教版九年级语文上册教案全集
- 辽宁省沈阳市沈河区沈阳市第七中学协作体2024-2025学年八年级上学期期中地理试卷(含答案)
- 广东省揭阳市2025届高三上学期第一次月考数学试题(含答案)
- 中医基础论述题
- 二 《学习工匠事迹 领略工匠风采》(教学设计)-【中职专用】高二语文精讲课堂(高教版2023·职业模块)
- 工程项目建设程序
- 中小学生劳动教育的跨学科融合案例
- 分子结构与化学性质的关系
- 医院内肺炎预防与控制标准操作规程
- 道路(光彩工程)亮化施工投标方案(技术方案)
- 2023年房地产估价师考试完整真题及答案解析
- 第14课 推进绿色发展
- 山东省泰安市新泰市2023-2024学年五年级上学期期中语文试卷
- 《机械设计》课程思政教学案例(一等奖)
评论
0/150
提交评论