JHTP自测题_第七章_数组及动态数组(Array and ArrayList)
来源:互联网 发布:mac 终端显示路径 编辑:程序博客网 时间:2024/05/01 20:28
很基础的问题,不容得出错;出错只能说明一个问题:基础不牢固。
Self-Review Exercises
7.1Fill in theblank(s) in each of the following statements:
a) Lists and tables ofvalues can be stored inArray and Collections.
b) An array is a group ofvariables(called elements or components) containing values that allhave the same type.
c) Theenhanced forstatement allows you to iterate through an array’s elements without using acounter.
d) The number used torefer to a particular array element is called the element’sindex (subscriptor position number).
e) An array that uses twoindices is referred to as a(n)two-dimensional array.
f) Use the enhancedforstatementfor(double n: numbers) to walk through doublearraynumbers.
g) Command-line argumentsare stored in anarray of String, called args by convention.
h) Use the expressionargs.lengthto receive the total number of arguments in a command line. Assume thatcommand-line arguments are stored inString[] args.
i) Given the commandjavaMyClass test, the first command-line argument istest.
j) A(n)ellipse(…)in the parameter list of a method indicates that the method can receive avariable number of arguments.
7.2Determinewhether each of the following istrueorfalse. Iffalse, explainwhy.
a) An array can storemany different types of values.False
b) An array index shouldnormally be of typefloat.False
c) An individual arrayelement that’s passed to a method and modified in that method will contain themodified value when the called method completes execution.False
d) Command-line argumentsare separated by commas.False
7.3Perform thefollowing tasks for an array calledfractions:
a) Declare a constantARRAY_SIZEthat’s initialized to 10. final int ARRAY_SIZE=10;
b) Declare an array withARRAY_SIZEelements of typedouble, and initialize theelements to0.double[] d=new double[ARRAY_SIZE];
c) Refer to array element4.d[4]
d) Assign the value1.667to arrayelement 9. d[9]=9;
e) Assign the value3.333to arrayelement 6. d[6]=6;
f) Sum all the elementsof the array, using aforstatement. Declare the integer variablexas a controlvariable for the loop.
double sum=0.0;
for (intx=0;x<d.length;x++){
sum+=d[x];
}
7.4Perform thefollowing tasks for an array calledtable:
a) Declare and create thearray as an integer array that has three rows and three columns.
Assume that the constantARRAY_SIZEhas been declared to be3.
int[][] i=new int[3][3];
b) How many elements doesthe array contain? 9
c) Use aforstatement toinitialize each element of the array to the sum of its indices. Assume that theinteger variablesxandyare declared as control variables.
7.5Find andcorrect the error in each of the following program segments:
a)final intARRAY_SIZE=5;
ARRAY_SIZE=10;
b) Assumeint[] b =new int[10];
for(inti =0; i <=b.length; i++)
b[i] =1;
c) Assumeint[][] a ={{1,2}, {3,4}};
a[1,1] =5;
- JHTP自测题_第七章_数组及动态数组(Array and ArrayList)
- JHTP小结_第七章_数组及动态数组(Array and ArrayList)
- JHTP自测题_第十三章_图形及Java2D
- JHTP自测题_第十四章_字符串、字符及正则表达式(Strings, Characters and Regular Expressions)
- JHTP自测题_第十二章_GUI组件(上篇)
- JHTP自测题_第十五章_文件、流和对象序列化(Files, Streams, and Object Serialization)
- JHTP自测题_第六章_深入理解方法
- JHTP自测题_第三章_类、对象、方法及字符串简介
- JHTP自测题_第九章_面向对象编程-继承(Inheritance)
- JHTP自测题_第十章_面向对象编程-多态(Polymorphism)
- JHTP自测题_第十一章_深入理解异常(Exception Handling)
- JHTP自测题_第二章_Java应用、输入、输出及运算符简介
- JHTP自测题_第一章_计算机、互联网及Java简介
- JHTP自测题_第四章_控制语句Part 1-赋值、++、--运算符
- JHTP自测题_第五章_控制语句Part 2-逻辑运算符
- JHTP自测题_第八章_深入理解类和对象
- JHTP小结_第十四章_字符串、字符及正则表达式(Strings, Characters and Regular Expressions)
- JHTP小结_第十三章_图形及Java2D
- 寻找Coder(去哪儿2016校招)
- 【GitHub】GitHub .gitignore文件简单配置使用
- 使用awk命令实现类sql功能
- 367. Valid Perfect Square我的做法
- 使用Android Studio遇到的问题及解决过程
- JHTP自测题_第七章_数组及动态数组(Array and ArrayList)
- 栈的C语言实现(链表)
- Windows下MySql5.6.24免安装版环境配置
- web.xml 配置介绍
- Python小记01 一些语法(和JAVA不同的)
- Java Script 函数基础知识
- ATT
- PDO预处理案例
- UNIX - 线程(1)