JAVA練習(xí)題含答案ANSWERSTOPRACTICE_第1頁(yè)
JAVA練習(xí)題含答案ANSWERSTOPRACTICE_第2頁(yè)
JAVA練習(xí)題含答案ANSWERSTOPRACTICE_第3頁(yè)
JAVA練習(xí)題含答案ANSWERSTOPRACTICE_第4頁(yè)
JAVA練習(xí)題含答案ANSWERSTOPRACTICE_第5頁(yè)
已閱讀5頁(yè),還剩6頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

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. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論