Programming Assignment VI
Programming Assignment VI
Programming Assignment VI
(Arrays)
(Programming using JAVA)
One-Dimensional Arrays:
1. Write a java program to create an array of size N and store the
random values in it and find the sum and average.
2. Write a java program to input 10 integers from keyboard and store
them into an array. Then find out how many of them are positive, how
many are negative, how many are even and how many are odd.
3. Input 10 integers from the keyboard into an array. The number to be
searched is entered through the keyboard by the user. Write a java
program to find if the number to be searched is present in the array and
if it is present, display the number of times it appears in the array.
4. Write a java program to find the maximum and minimum and how
many times they both occur in an array of n elements. Find out the
positions where the maximum first occurs and the minimum last
occurs.
5. Write a java program to find the second largest value in an array of
n elements.
6. There are 500 light bulbs (numbered 1 to 500) arranged in a row.
Initially they are all OFF. Starting with bulb 2, all even numbered bulbs
are turned ON. Next, starting with bulb 3, and visiting every third bulb,
it is turned ON if it is OFF, and it is turned OFF if it is ON. This
procedure is repeated for every fourth bulb, then every fifth bulb, and
so on up to the 500th bulb. Write a java program to determine which
bulbs are OFF at the end of above exercise.
7. Write a program in java to insert n number through Keyboard and
check which of the numbers are perfect numbers and count the total
numbers of perfect numbers are present.
8. Write a program to merge two arrays of size m and n
respectively. The resultant array is of size m+n.
Two-Dimensional Arrays:
7. Suppose a teacher with M students and N Marks of each student is
maintained in an (M+1)-by-(N+1) array, reserving the last column for
each student’s average mark and the last row for average test mark.
Write a java program to compute the average mark for each student .
(Average values of each row) and calculate the average test mark
(average values of each column).
8. Write a java program to find the addition of two matrices. After
inserting the two matrices first display the both matrices and then add
them and show the result.
9. Write a java program to transpose a square two-dimensional array in
place without creating a second array.
10. Write a java program to multiply two rectangular matrices that are
not necessarily square.
Note: For the dot product to be well-defined, the number of columns in
the first matrix must be equal to the number of rows in the second
matrix. Print an error message if the dimensions do not satisfy this
condition.
11. Write a java Program to find the Determinant of a Matrix of size
N*N entered through the keyboard.
12. Write a java program to find the Normal and Trace of a 2D Matrix
entered through the keyboard.
Note: Normal of a matrix is defined as the square root of the sum of
squares of all the elements of the matrix.
Trace of a given square matrix is defined as the sum of all the
elements in the diagonal .
13. Write a java program to rotate matrix element in clockwise
direction.