Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1.) Which of the following is a correct way to declare an int array. a.) int[] array; b.) int array; c.) int array[]; d.)Array[int] array

1.) Which of the following is a correct way to declare an int array.

a.) int[] array;
b.) int array;
c.) int array[];
d.)Array[int] array

2.)Which of the following to is a correct way to declare and initialize an array of integers with length 10?

a.) int[] array = new int[10];
b.) int[10] array = new int[10];
c) int[10] array = new int[];
d) int array = new int[10];

3.)Which of the following is a correct way to declare and initialize an array with values 1,2,3,4,5 ?

a.) int[] arr = {1,2,3,4,5};
b.) int[] arr = [1,2,3,4,5];
c.) int arr = {1,2,3,4,5};
d.) int[] arr = new int[1,2,3,4,5];

4)What is x[0] in the following code?

int[ ] x = {1,2,3};

a) 1
b) 2
c) 3
d) None of the above

5)What type of data type would you create if a user wants to enter 50 names?

a) String[ ] Array
b) String Array
c) char Array
d) char[ ] Array

6)Will the following code compile or no?

int[ ] x = new int[3];

x = {1,2,3};

a) No, because you need to reinitialize the array if you do it this way.
b) Yes, because you already initialized it above with no values.

7)Each element in the array is represented using the following syntax, known as an ________ , ________ .

8)You change a length of the array once it is initialized without reinitializing the array. True or False?

a) True
b) False

9)Look at the line of code below. Which of the following answer choices can be used to print the last element of array x?

String[ ] x = {"Tom", "Bob", "Jerry", "Cat"};

Note that the last element is "Cat", and x.length returns the size of the array (in this case, 4). Also notice that we use x.length for arrays, while for Strings, it is someString.length().

a.)System.out.print(x[0]);
b.)System.out.print(x[length]);
c.) System.out.print(x[x.length]);
d.) System.out.print(x[x.length-1]);
e.)

System.out.print(x[4]);

10)Which of the following to is a correct way to declare a String array?

a)String[] array;
b)String array;
c)String array[];
d)Array[String] array;

11) How do you declare an array variable? (Write a code snippet.) Note that you aren't initializing anything yet, but simply declaring it?

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Genomes And Databases On The Internet A Practical Guide To Functions And Applications

Authors: Paul Rangel

1st Edition

189848631X, 978-1898486312

More Books

Students also viewed these Databases questions