Page 349 - Cs_withBlue_J_C11_Flipbook
P. 349
Unsolved Questions
A. Tick ( ) the correct answer:
1. Which of the following is the correct statement to declare and initialise an array?
a. int ar[ ] = [3, 5, 7]; b. int[ ] ar = [3, 5, 7];
c. int ar[ ] = {3, 5, 7}; d. int [ ] ar = {3, 5, 7};
2. Binary search is also known as ………………… .
a. Middle search b. Half search
c. Half-interval search d. Middle-interval search
3. We use the array name and the element’s ………………… to access the element.
a. data type b. subscript
c. name d. value
4. Which of the following statements can be used to create a one-dimensional array ar of size 5 with double type values?
a. double [5] ar; b. double [5] = ar;
c. double ar[] = ar[5]; d. double ar[5];
5. The ………………… sort usually performs less interchanges than the ………………… sort.
a. bubble, insertion b. bubble, selection
c. selection, bubble d. selection, insertion
B. Fill in the blanks:
1. Index in an array starts with ………………… .
2. ………………… search is also known as sequential search.
3. ………………… is the process of combining two or more arrays.
4. Array can be initialised using ………………… as a separator surrounded by curly braces.
5. The ………………… class is used to take input from the user in arrays.
C. Answer the following questions:
1. What is a 2D array?
2. What do you mean by sorting?
3. Define bubble sort.
4. What is insertion sort?
D. Unsolved Programs:
1. Write a program in Java to input 10 positive and negative numbers each and calculate the following:
a. sum of odd numbers in an array
b. product of all the multiples of 7.
2. Write a program in Java to input 20 names in an array and print the names in ascending order using the bubble sort method.
3. Write a program in Java to store 25 numbers in a single-dimensional array and arrange them in descending order by using
insertion sort.
4. Write a Java program to input 10 numbers and print the prime numbers only.
5. Write a program in Java to create an array of 5 elements and using switch case do the following.
Case 1: prints the sum of all the prime numbers
Case 2: print all the odd negative numbers
6. Write a Java program to create an array of size 2 × 3 and print the factorial of all the numbers separately.
7. Write a program in Java to accept the item names and prices of some items in two single-dimensional arrays and calculate the
total amount to be paid by the customer. Display in the following manner:
Item Name Price
– –
– –
Total Amount –
347
Arrays 347

