0% found this document useful (0 votes)
7 views3 pages

Array Worksheet

Uploaded by

Krishna Kanodia
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views3 pages

Array Worksheet

Uploaded by

Krishna Kanodia
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Q1. Define a class to accept values into an array.

If not, output the message "Record


integer array of order 4 x 4 and check does not exist". (1982 1987 1993 1996 1999
whether it is a DIAGONAL array or not. An 2003 2006 2007 2009 2010).
array is DIAGONAL if the sum of the left Q7. Write a program to accept 20 integer
diagonal elements equals the sum of the numbers in a single Dimensional Array. Find
right diagonal elements. Print the and display the following: i. Number of even
appropriate message. Example: numbers. ii. Number of odd numbers. iii.
3425 Number of multiples of 4.
2523
5327 Q8. Write a program in Java to accept 20
1371 numbers in a single dimensional array
Sum of the left diagonal element = 3 + 5 + 2 arr[20]. Transfer and store all the even
+ 1 = 11 numbers in an array even[ ] and all the odd
Sum of the right diagonal element = 5+2 + numbers in another array odd[ ]. Finally,
3 + 1 = 11 print the elements of both the arrays.
Q2. Define a class to accept values into a 3 Q9. Define a class pin code and store the
× 3 array and check if it is a special array. An given pin codes in a single dimensional array.
array is a special array if the sum of the even Sort these pin codes in ascending order
elements = sum of the odd elements. using the Selection Sort technique only.
Example: Display the sorted array.
A[ ][ ]={{ 4 ,5, 6}, { 5 ,3, 2}, { 4, 2, 5}}; 110061, 110001, 110029, 110023, 110055,
Sum of even elements = 4 + 6 + 2 + 4 + 2 110006, 110019, 110033
= 18 Q10. Define a class to accept values in
Sum of odd elements = 5 + 5 + 3 + 5 = 18 integer array of size 10. Sort them in an
Q3. Define a class to accept values into 4x4 ascending order using selection sort
array and find and display the sum of each technique. Display the sorted array.
row. Q11. Define a class to accept 10 characters
Example: from a user. Using bubble sort technique
A[]={ 1,2,3,4 },{5,6,7,8},{ 1,3,5,7}, arrange them in ascending order. Display the
{2,5,3,1}} sorted array and original array.
Output: Q12. Define a class to accept values into an
sum of row 1 =10 (1+2+3+4) array of double data type of size 20. Accept a
sum of row 2= 26 (5+6+7+8) double value from user and search in the
sum of row 3=16 (1+3+5+7) array using linear search method. If value is
sum of row 4= 11 (2+5+ 3+ 1) found display message "Found" with its
Q4. Define a class to search for a value input position where it is present in the array.
by the user from the list of values given Otherwise display message "not found".
below. If it is found display the message Q13. Define a class to accept values in
"Search successful", otherwise display the integer array of size 10. Find sum of one digit
message "Search element not found" using number and sum of two-digit numbers
Binary search technique. entered. Display them separately. Example:
5.6, 11.5, 20.8, 35.4, 43.1, 52.4, 66.6, 78.9, Input: a[ ] = {2, 12, 4, 9, 18, 25, 3, 32, 20,
80.0, 95.5. 1}
Q5. Write a program to accept 10 different Output:
names in a Single Dimensional array SDA. Sum of one-digit numbers: 2+4+9+3+1=19
Now enter a name and search whether the Sum of two-digit numbers:
name is present or not in the list of array 12+18+25+32+20=107
elements by using the "linear search" Q14. Define a class to perform binary search
technique. on a list of integers given below, to search
Q6. Write a program to accept the year of for an element input by the user, if it is found
graduation from school as an integer value display the element along with its position,
from the user. Using the binary search otherwise display the message "Search
technique on the sorted array of integers element not found".
given below, output the message "Record 2, 5, 7, 10, 15, 20, 29, 30, 46, 50
exists" if the value input is located in the
Q15. Define a class to declare a character Q21. Define a class to accept values into
array of size ten. Accept the characters into 4x4 array and find and display the elements
the array and display the characters with of primary diagonal and secondary diagonal.
highest and lowest ASCII (American Standard Example:
Code for Information Interchange) value. 1 2 3 4
EXAMPLE: 5 6 7 8
INPUT: 'R', 'z', 'q', 'A', 'N', 'p', 'm', 'U', 'Q', 'F' 1 3 5 7
OUTPUT: 2 5 3 1
Character with highest ASCII value = z Output:
Character with lowest ASCII value = A Primary diagonal = 1,6,5,1
Q16. Define a class to declare an array of Secondary diagonal = 4,7,3,2
size twenty of double datatype, accept the Q22. Define a class to accept values into
elements into the array and perform the 4x4 array and find and display the elements
following: of above and below left diagonal.
Calculate and print the product of all the Example:
elements. Print the square of each element 1 2 3 4
of the array. 5 6 7 8
Q17. Write a program to input 15 integer 1 3 5 7
elements in an array and sort them in 2 5 3 1
ascending order using the bubble sort Output:
technique. Elements above left diagonal = 2,3,4,7,8,7
Q18. Write a program to accept name and Elements below left diagonal = 5,1,3,2,5,3
total marks of N number of students in two
single subscript array name[] and Q23. Define a class to accept values into
totalmarks[]. 4x4 array and find and display the elements
Calculate and print: of above and below right diagonal.
i) The average of the total marks obtained Section A
by N number of students. Q1. Which element is num[9] of array num?
[average = (sum of total marks of all the Q2. If int a[] = {7, 3, 4, 8, 9, 2}; what are
students)/N] the values of x and y?
ii) Deviation of each student’s total marks (a) x = a[1] * a[0] + a[3]
with the the average. (b) y = a.length
[deviation = total marks of a student – Q3. What will be the output of the following
average] code?
Q19. Write a program to input integer String a[] = {"MI", "Samsung", "Micromax",
elements into an array of size 20 and "One Plus"};
perform the following operations: System.out.println(a[3].length());
1. Display largest number from the array. Q4. Given array int Z[ ] = {15, 16, 17} ; it
2. Display smallest number from the will occupy ............... bytes in memory.
array. Q5. In ............... search, the algorithm uses
3. Display sum of all the elements of the the middle value of the array for the search
array operation.
Q20. Define a class to accept values into Q6. A single dimensional array contains N
3x5 array and find and display the sum of elements. What will be the last subscript?
each column. Q7. Given array int x[ ] = {11, 22, 33, 44};
Example: the value of x[1 + 2] is
A[][]={ {1,2,3,4,7},{5,6,7,8,9},{1,3,5,7,10}, Q8. State the number of bytes and bits
{2,5,3,1,5}} occupied by a character array of 20
Output: elements.
sum of column 1 =9 (1+5+1+2) Q9. The number of bytes occupied by a
sum of column 2= 16 (2+6+3+5) character array of four rows and three
sum of column 3= 18 (3+7+5+3) columns are
sum of column 4= 20 (4+8+ 7+ 1) Q10. Consider the following two-dimensional
sum of column 5= 31 (7+9+ 10+ 5) array and answer the questions given below:
int x[ ][ ] = {{4,3,2}, {7,8,2}, {8, 3,10}, {1,
2, 9}};
(a) What is the order of the array?
(b) What is the value of x[0][0]+x[2][2]?
Q11. Java statement to access the 5th
element of an array is:
Q12. int P[ ] = {12, 14, 16, 18};
int Q[ ] = {20, 22, 24};
Place all elements of P array and Q array in
the array R one after the other.
(a) What will be the size of array R[ ] ?
(b) Write index position of first and last
element?
Q13. If int arr[ ] = {2, 1, 6, 7, 3); then what
is the value of variable a, if
a=arr.length+arr[4];
Q14. What will the following program part
display?
int a[ ]= {15, 2, 8, 100, 64};
System.out.println(Math.pow(Math.cbrt
(a[2]),a[1]));
Q15. Given: int A [ ] [ ] = {{8, 9, 2}, {4, 6,
2},{11,5,10}};
What will be the value of A [1][2] + A [2][0]?
Q16. Analyse the following program segment
and write its output.
double d[ ]={25.00, 12.00, 36.00, 0.25,
2.00};
d[1] = 10;
System.out.println(Math.sqrt(d[0]) + 3.00 +
d[1]);

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy