《Java语言程序设计:基础篇》课后复习题答案-第六章

更新时间:2023-08-08 17:28:11 阅读: 评论:0

Chapter6Single-dimensional Arrays
1.See the ction"Declaring and Creating Arrays."
2.You access an array using its index.
3.No memory is allocated when an array is declared.The memory is allocated when
creating the array.
x is60
The size of numbers is30
4.Indicate true or fal for the following statements:
1.Every element in an array has the same type.
Answer:True
2.The array size is fixed after it is declared.
possible什么意思
Answer:Fal
3.The array size is fixed after it is created.
Answer:True
4.The element in the array must be of primitive data type.
Answer:Fal
5.Which of the following statements are valid array declarations?
int i=new int(30);
succeedsAnswer:Invalid
double d[]=new double[30];
Answer:Valid
char[]r=new char(1..30);
Answer:Invalid
int i[]=(3,4,3,2);
Answer:Invalid
float f[]={2.3,  4.5,  5.6};
Answer:Valid
char[]c=new char();
Answer:Invalid
6.The array index type is int and its lowest index is0.
a[2]
7.
(a)
double[]list=new double[10];
(b)
list[list.length–1]=5.5;
(c)
服装设计师手稿网站
System.out.println(list[0]+list[1]);
(d)
double sum=0;
for(int i=0;i<list.length;i++)
sum+=list[i];
(e)
double min=list[0];
for(int i=1;i<list.length;i++)
if(min>list[i])min=list[i];
(f)
System.out.println(list[(int)(Math.random()*list.length));
(g)
double[]={3.5,  5.5,  4.52,  5.6};
8.A runtime exception occurs.
9.Line3:the array declaration is wrong.It should be double[].The array needs to
be created before its w double[10]
Line5:The micolon(;)at the end of the for loop heading should be removed.
Line5:r.length()should be r.length.
Line6:random should be random()
Line6:r(i)should be r[i].
wch
10.System.arraycopy(source,0,t,0,source.length);
11.The cond assignment statement myList=new int[20]creates a new array and
assigns its reference to myList.
myList new int[10]
Array myList new int[10]
Array
new int[20]
Array
12.Fal.When an array is pasd to a method,the reference value of the array is
pasd.No new array is created.Both argument and parameter point to the same
array.
13.
numbers is 0and numbers[0]is3
14.
(A) Executing
createArray in Line 6
Space required for the main method
char[] chars: ref
Heap Array of 100 characters
Space required for the createArray method
char[] chars: ref
(B) After exiting
createArray in Line 6
Space required for the
main method
char[] chars: ref
Heap
Array of 100crayons怎么读
characters
Stack Stack (C) Executing
displayArray in Line 10
velcadeSpace required for the main method
char[] chars: ref
Heap Array of 100 characters
Space required for the displayArray method
char[] chars: ref
(D) After exiting
displayArray in Line
10
Space required for the
main method
char[] chars: ref
初中数学补习辅导课程Heap
Array of 100
characters
Stack Stack
(E) Executing countLetters in Line 13
Space required for the main method
int[] counts: ref
char[] chars: ref
Heap Array of 100 characters
Space required for the countLetters method
int[] counts: ref
char[] chars: ref (F) After exiting
countLetters in Line 13
配料英文Space required for the
main method
int[] counts: ref
char[] chars: ref
Heap
Array of 100
characters
Stack Stack
Array of 26 integers Array of 26 integers
(G) Executing displayCounts in Line 18
Space required for the main method
int[] counts: ref
char[] chars: ref
Heap Array of 100 characters
印尼语Space required for the displayCounts method
int[] counts: ref (H) After exiting
displayCounts in Line 18
Space required for the
main method
int[] counts: ref
char[] chars: ref
Heap
Array of 100
characters
Stack Stack
Array of 26 integers Array of 26 integers
15.Only one variable-length parameter may be specified in
a method and this parameter must be the last parameter.The method return type cannot be a variable-length parameter.
16.The last one
printMax(new int[]{1,2,3});
is incorrect,becau the array must of the double[] type.
17.Omitted
18.Omitted
19.Omitted
20Simply change(currentMax<list[j])on Line10to (currentMax>list[j])
21Simply change list[k]>currentElement on Line9to
list[k]<currentElement
22.You can sort an array of any primitive types except boolean.The sort method is void,
马耳他英语so it does not return a new array.
23.To apply java.util.Arrays.binarySearch(array,key),the array must be sorted in increasing order.
24.Line1:list is{2,4,7,10}
Line2:list is{7,7,7,7}
Line3:list is{7,8,8,7}
Line4:list is{7,8,8,7}

本文发布于:2023-08-08 17:28:11,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/90/191714.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:辅导   设计师   课程   网站   服装   补习   数学
相关文章
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图