Page 350 - Cs_withBlue_J_C11_Flipbook
P. 350
8. Write a Java program to input "n" numbers and store the odd numbers and even numbers separately in two different arrays.
9. Write a program in Java to accept the names and marks in computer science of forty students in an array and then print the
names and marks of students according to their merit.
10. Write a Java program to find the common elements between two arrays A and B and print them.
11. Write a program in Java that reads the following list of countries and their respective cities into two separate one-dimensional
arrays. The program should accept the name of a country as input and give the name of the corresponding city as an output. The
program should display an error message when the user enters the country which is not mentioned in the given list. To stop the
program, "XXX" is to be entered as input.
GERMANY BERLIN
NEPAL KATMANDU
JAPAN TOKYO
CANADA MONTREAL
IRAQ BAGHDAD
12. The annual examination result of 50 students in a class is tabulated as follows:
Roll No. Subject A Subject B Subject C
– – – –
Write a Java program to read the data, calculate and display the following:
a. Average marks obtained by each student.
b. Print the roll number and average marks of the students whose average mark is above 80.
13. Write a program in Java to store the names of the 10 politicians and their parties to which they belong to in two separate arrays.
Ask the users to enter the name of the party. Print out all the names of the politicians who belong to that party. Repeat the
process according to user choice.
14. Write a Java program to generate 10 terms of the Fibonacci series in a single-dimensional array.
15. Write a Java program to input 10 different numbers and arrange them in such a way that all the even numbers are arranged in
ascending order followed by all odd numbers.
16. Create a square matrix of size M × M and check whether it is a symmetric matrix or not. A symmetric matrix is a square matrix
that is equal to its transpose.
17. Write a program in Java to generate a Pascal triangle in which each number in the row is the sum of the two numbers immediately
above it. The program should print the first six rows of the triangle.
(Hint: E[J.I] = P[I-1,J-1] + P[I-1,J] is true for all elements but the boundary elements which are all equal to 1)
18. Write a program in Java to input elements in a 3x3 matrix and swap the numbers of the 1st row with the 3rd row of a given matrix.
19. Write a program in Java to create a 3x3 matrix and print the highest value of each column in the following manner.
5 7 4
4 6 2
8 2 10
Highest value in column 1 = 8
Highest value in column 2 = 7
Highest value in column 3 = 10
20. Write a Java program to declare a square matrix M [ ] [ ] of order ‘N’ where ‘N’ must be greater than 3 and less than 10. Allow the
user to accept three different characters from the keyboard and fill the array according to the instructions given below:
(i) Fill the four corners of the square matrix by character 1.
(ii) Fill the boundary elements of the matrix (except the four corners) by character 2.
(iii) Fill the non-boundary elements of the matrix by character 3.
Test your program with the following data and some random data:
INPUT: N = 4
FIRST CHARACTER : @
SECOND CHARACTER : ?
THIRD CHARACTER : #
348348 Touchpad Computer Science-XI

