1)Suppose your method does not return any value, which of the following keywords can be used as a return type?
A)void  B)public  C)int  D)double  E)None of the above

2)The signature(函数签名) of a method consists of ________.  
A)method name and parameter list
B)parameter list
C)return type, method name, and parameter list
D)method name

3)All Java applications must have a method ________.   
A)public static Main(String args[ ])
B)public static void main(String[ ] args)
C)public static Main(String[ ] args)
D)public static main(String[ ] args)
E)public void main(String[ ] args)

4)Arguments to methods always appear within ________.
A)parentheses  B) quotation marks  C)curly braces  D) brackets

parentheses 括号 函数的参数出现在括号中

  
5)Does the return statement in the following method cause compile errors?

public static void main(String[ ] args) {
int max = 0;
if (max != 0)
System.out.println(max);
else
return;
}

A)Yes B) No

6)Does the method call in the following method cause compile errors?

public static void main(String[ ] args) {
Math.pow(2, 4);
}

A)Yes B) No

7)Each time a method is invoked, the system stores parameters and local variables in an area of memory, known as ________, which stores elements in last-in first-out fashion.
A)a stack  B) a heap  C)an array  D) storage area

8)Which of the following should be declared as a void method?   
A)Write a method that prints integers from 1 to 100.
B)Write a method that converts an uppercase letter to lowercase.
C)Write a method that checks whether current second is an integer from 1 to 100.
D)Write a method that returns a random integer from 1 to 100.

注意题目要求是没有返回值void类型的

9)When you invoke a method with a parameter, the value of the argument is passed to the parameter. This is referred to as ________.
A)pass by reference  B) pass by value  C)pass by name  D) method invocation

值传递

10)Given the following method

static void nPrint(String message, int n) {
while (n > 0) {
System.out.print(message);
n--;
}
}

What is the printout of the call nPrint('a', 4)?  
A)invalid call  B) aaaa  C)aaaaa  D) aaa

'a'是char类型

The method nPrint(String, int) in the type test is not applicable for the arguments (char, int)

11)Given the following method

static void nPrint(String message, int n) {
while (n > 0) {
System.out.print(message);
n--;
}
}

What is k after invoking nPrint("A message", k)?
int k = 2;
nPrint("A message", k);
A)2 B) 1 C) 0 D) 3

这里的传递方式是值传递,并不会改变实参的值。

12)Analyze the following code:

public class Test {
public static void main(String[ ] args) {
System.out.println(xMethod(5, 500L));
}
public static int xMethod(int n, long l) {
System.out.println("int, long");
return n;
}
public static long xMethod(long n, long l) {
System.out.println("long, long");
return n;
}
}

A)The program runs fine but displays things other than 5.
B)The program displays long, long followed by 5.
C)The program displays int, long followed by 5.
D)The program does not compile because the compiler cannot distinguish which xmethod to invoke.

13)Analyze the following code:

class Test {
public static void main(String[ ] args) {
System.out.println(xmethod(5));
}
public static int xmethod(int n, long t) {
System.out.println("int");
return n;
}
public static long xmethod(long n) {
System.out.println("long");
return n;
}
}

A)The program runs fine but displays things other than 5.
B)The program displays int followed by 5.
C)The program displays long followed by 5.
D)The program does not compile because the compiler cannot distinguish which xmethod to invoke.

14)Analyze the following code.

public class Test {
public static void main(String[ ] args) {
System.out.println(max(1, 2));
}
public static double max(int num1, double num2) {
System.out.println("max(int, double) is invoked");
if (num1 > num2)
return num1;
else
return num2;
}
public static double max(double num1, int num2) {
System.out.println("max(double, int) is invoked");
if (num1 > num2)
return num1;
else
return num2;
}
}

A)The program runs and prints 2 followed by "max(int, double)" is invoked.
B)The program runs and prints 2 followed by "max(double, int)" is invoked.
C)The program cannot compile because the compiler cannot determine which max method should be invoked.
D)The program runs and prints "max(int, double) is invoked" followed by 2.
E)The program cannot compile because you cannot have the print statement in a non-void method.

15)Analyze the following code.

public class Test {
public static void main(String[ ] args) {
System.out.println(m(2));
}
public static int m(int num) {
return num;
}
public static void m(int num) {
System.out.println(num);
}
}

A)The program has a compile error because the two methods m have the same signature.
B)The program runs and prints 2 twice.
C)The program runs and prints 2 once.
D)The program has a compile error because the second m method is defined, but not invoked in the main method.

16)What is k after the following block executes?

{
int k = 2;
nPrint("A message", k);
}
System.out.println(k);

A)2  B)1  C)0  D)k is not defined outside the block. So, the program has a compile error

17)A variable defined inside a method is referred to as ________.   
A)a method variable  B) a global variable  C)a block variable  D) a local variable

局部变量
18)The client can use a method without knowing how it is implemented. The details of the implementation are encapsulated in the method and hidden from the client who invokes the method. This is known as ________. (Choose all that apply.)
A)encapsulation  B) information hiding  C)simplifying method  D) method hiding

封装和信息隐藏

19)Which of the following is a possible output from invoking Math.random()? (Choose all that apply.)
A)1.0 B) 0.5 C) 3.43 D) 0.0

20)What is Math.round(3.6)?
A)4 B) 3 C) 4.0 D) 3.0

Math.round四舍五入取整

21)What is Math.rint(3.6)?
A)3.0 B) 5.0 C) 4.0 D) 3

Math.rint返回最接近这个数的整数,如果刚好居中,则取偶数 

22)What is Math.rint(3.5)?
A)3.0 B) 3 C) 5.0 D) 4.0 E) 4

23)What is Math.ceil(3.6)?
A)5.0 B) 3.0 C) 3 D) 4.0

Math.ceil向上取整

24)What is Math.floor(3.6)?
A)4 B) 3.0 C) 3 D) 5.0

Math.floor向下取整

25)(int)(Math.random() * (65535 + 1)) returns a random number ________.
A)between 1 and 65536  B) between 0 and 65535  
C)between 1 and 65535  D) between 0 and 65536

26)(int)('a' + Math.random() * ('z' - 'a' + 1)) returns a random number ________.   
A)between 'a' and 'z' B) between 0 and (int)'z' C)between 'a' and 'y' D) between (int)'a' and (int)'z'

注意这里的类型是int!

27)(char)('a' + Math.random() * ('z' - 'a' + 1)) returns a random character ________.
A)between 'b' and 'y' B) between 'b' and 'z' C)between 'a' and 'z' D) between 'a' and 'y'

28)Which of the following is the best for generating random integer 0 or 1?   
A)(int)Math.random() + 1
B)(int)(Math.random() + 0.8)
C)(int)(Math.random() + 0.2)
D)(int)Math.random()
E)(int)(Math.random() + 0.5)

29)________ is to implement one method in the structure chart at a time from the top to the bottom.
A)Top-down approach
B)Bottom-up and top-down approach
C)Bottom-up approach
D)Stepwise refinement

自顶向下的方式是在结构图中从上到下依次实现一个方法。

30)________ is a simple but incomplete version of a method.
A)A stub
B)A main method
C)A method developed using top-down approach
D)A non-main method

待实现的方法可以用存根方法(stub)代替,存根方法是方法的一个简单但不完整的版本。

使用存根方法可以快速地构建程序的框架

Java题库——Chapter5 方法的更多相关文章

  1. Java题库——Chapter13抽象类和接口

    )What is the output of running class Test? public class Test { public static void main(String[ ] arg ...

  2. Java题库——Chapter8 对象和类

    1)________ represents an entity(实体) in the real world that can be distinctly identified. 1) _______ ...

  3. acm之poj题库1001方法

    题目所言是银行等不能用四舍五入等影响精度的方法来计算的情况,是为提出背景.因此需要特殊的编写.这里使用了好几种方法才找到一个合适的方法.因为C++或者C缺乏类库,又跟底层关联太大,缺乏常用的类库,在写 ...

  4. Java题库——Chapter17 二进制I/0

    Introduction to Java Programming 的最后一章,完结撒花!Chapter 17 Binary I/O Section 17.2 How is I/O Handled in ...

  5. Java题库——Chapter14 JavaFX基础

    Chapter 14 JavaFX Basics Section 14.2 JavaFX vs Swing and AWT1. Why is JavaFX preferred?a. JavaFX is ...

  6. Java题库——Chapter12 异常处理和文本IO

    异常处理 1)What is displayed on the console when running the following program? class Test { public stat ...

  7. Java题库——Chapter11 继承和多态

    1)Analyze the following code: public class Test { public static void main(String[ ] args) { B b = ne ...

  8. Java题库——Chapter10 面向对象思考

    1)You can declare two variables with the same name in ________. 1) _______ A)a method one as a forma ...

  9. Java题库——Chapter9 String的用法

    1)Which code fragment would correctly identify the number of arguments passed via the command line t ...

随机推荐

  1. Laravel 中使用 swoole 项目实战开发案例二 (后端主动分场景给界面推送消息)

    推荐阅读:Laravel 中使用 swoole 项目实战开发案例一 (建立 swoole 和前端通信)​ 需求分析 我们假设有一个需求,我在后端点击按钮 1,首页弹出 “后端触发了按钮 1”.后端点了 ...

  2. 剑指Offer-46.孩子们的游戏(圆圈中最后剩下的数)(C++/Java)

    题目: 每年六一儿童节,牛客都会准备一些小礼物去看望孤儿院的小朋友,今年亦是如此.HF作为牛客的资深元老,自然也准备了一些小游戏.其中,有个游戏是这样的:首先,让小朋友们围成一个大圈.然后,他随机指定 ...

  3. 使用where 过滤数据

    --本章主要内容是MySQL中使用where搜索条件进行过滤数据. where条件在from子句后面给出,如下所示: select name,price from shops where price& ...

  4. java8-date和timeAPI

    一 我们为什么要学习 java.timeAPI 原先的Date and Calendar 类的api比较复杂,不易于理解,应用起来不是很灵活. Calendar 是个线程不安全的类会导致SimpleD ...

  5. minicom配置1500000波特率

    背景 项目需求,得用1500000波特率进行,即1.5M的波特率进行串口通信. 最开始以为minicom不支持,因为第一眼在配置界面的选项中没看见.后来发现其实是支持的 方式一 启动时带参数 -b 1 ...

  6. 新人踩坑的一天——springboot注入mapper时出现java.lang.NullPointerException: null

    来公司的第二周接到了定时任务的开发需求:每天早上十点发送用户报表邮件 .校招新人菜鸟没做过这玩意有些懵(尴尬)于是决定分步写,从excel导出->邮件发送->定时器实现->mappe ...

  7. JS---案例:设置div的宽度

    案例:设置div的宽度 <!DOCTYPE html> <html lang="en"> <head> <meta charset=&qu ...

  8. SpringBoot Restful Crud

    一个简单的Restful Crud实验 默认首页的访问设置: // 注册 自定义的mvc组件,所有的WebMvcConfigurer组件都会一起起作用 @Bean public WebMvcConfi ...

  9. 中移动物联手机端APP软件

    https://open.iot.10086.cn/doc/book/device-develop/multpro/sdk-doc-tool/APP.html

  10. C# 网络编程之简易聊天示例

    还记得刚刚开始接触编程开发时,傻傻的将网站开发和网络编程混为一谈,常常因分不清楚而引为笑柄.后来勉强分清楚,又因为各种各样的协议端口之类的名词而倍感神秘,所以为了揭开网络编程的神秘面纱,本文尝试以一个 ...