Q&A On Array In Java


Q Do arrays have to begin with an element 0, or could they range from a higher minimum number to a higher maximum number, such as 65 to 90?

A
No, but it is more efficient to do so because it takes up less memory in the computer to store arrays that begin with 0. You can use arrays of a higher index number simply by referring to the numbers you want to use. For example, if you created a for loop that cycled from array element 65 to element 90, you could disregard any other element numbers. However, there still will be array elements numbered from 0 to 64 taking up space in memory, even if you don't use them for anything.

Q Why are some errors called exceptions?

A
The significance of the term is that a program normally runs without any problems, and the exception signals an exceptional circumstance that must be dealt with. Exceptions are warning messages that are sent from within a Java program.

Q Can the length variable be set to increase or decrease the size of an array after it has been
created?

A
There's no way to modify the size of an array after it has been created;
length is strictly used to find out an array's upper boundary.

Quiz

If the brain were an array, you could test its length by answering each of the following questions about arrays.

Questions

1. What types of information are arrays best suited for?

(a) Lists
(b) Pairs of related information
(c) Trivia

2.
What variable can be used to check the upper boundary of an array?

(a)
top
(b)
length
(c) limit

3.
Who is the famous Aztec priest-ruler?

(a) Quisp
(b) Quetzalcoatl
(c) Quichelorraine

Answers

1. a. Lists that contain nothing but the same type of information--strings, numbers, and so on--are well-suited for storage in arrays.

2.
b.

3.
b. It's also the name of a god of learning and civilization who is depicted as an approaching storm whose winds kick up dust before the rain comes.

Activities

To give yourself an array of experiences to draw from later on, you can expand your knowledge of this hour's topics with the following activities:

·         Create a program that uses a multidimensional array to store student grades. The first dimension should be a number for each student, and the second dimension should be for each student's grades. Display the average of all the grades earned by each student and an overall average for every student.

·         Write a program that stores the first 400 prime numbers in an array.

 

 

 

 

 

Post a Comment

Previous Post Next Post