0% found this document useful (0 votes)
14 views16 pages

Java 62.1

Uploaded by

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

Java 62.1

Uploaded by

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

MUTHU BHAVANI D 710723104062

EXP NO: 2.1


SUM OF EACH ROW AND EACH COLUMN
DATE:

PROBLEM STATEMENT:-
Write a program to obtain a matrix and find the sum of each row and each column.
Input format :
The first line of the input consists of the number of rows M and columns N separated by
space.
The next M lines of input consist of N elements in each line separated by space.
Output format :
The output prints the sum of each row and each column, separated by a line.
Refer to the sample outputs for the formatting specifications.
Code constraints :
1 <= M, N <= 10
-1000 <= elements <= 1000

22UIT304 – JAVA PROGRAMMING LABORATORY


MUTHU BHAVANI D 710723104062

AIM:-

ALGORITHM:-

22UIT304 – JAVA PROGRAMMING LABORATORY


MUTHU BHAVANI D 710723104062

PROGRAM:-

OUTPUT:-

22UIT304 – JAVA PROGRAMMING LABORATORY


MUTHU BHAVANI D 710723104062

RESULT:-

22UIT304 – JAVA PROGRAMMING LABORATORY


MUTHU BHAVANI D 710723104062

EXP NO: 2.2


EVEN AND ODD ELEMENTS IN AN ARRAY
DATE:

PROBLEM STATEMENT:-
In an array, Ravi is trying to determine how many odd and even elements there are. Aid him
in locating the same.
Write a program that counts the array's odd and even elements.
Input format :
The first line of the input consists of the value of n.
The second line consists of an array of elements separated by a space.
Output format :
The first line of the output consists of the number of even elements.
The second line of the output consists of the number of odd elements.
Refer to the sample output for the formatting specifications.
Code constraints :
1 <= n <= 10
-1000 <= elements <= 1000

22UIT304 – JAVA PROGRAMMING LABORATORY


MUTHU BHAVANI D 710723104062

AIM:-

ALGORITHM:-

22UIT304 – JAVA PROGRAMMING LABORATORY


MUTHU BHAVANI D 710723104062

PROGRAM:-

OUTPUT:-

22UIT304 – JAVA PROGRAMMING LABORATORY


MUTHU BHAVANI D 710723104062

RESULT:-

22UIT304 – JAVA PROGRAMMING LABORATORY


MUTHU BHAVANI D 710723104062

EXP NO: 2.3


LOWER TRIANGULAR MATRIX
DATE:

PROBLEM STATEMENT:-
Rithu is studying matrices in her computer science class, and she is intrigued by the concept
of lower triangular matrices. She wants to write a program that takes a square matrix as input
and transforms it into its corresponding lower triangular matrix.
Write a Java program that prompts the user for a square matrix, processes it to create the
lower triangular matrix, and then displays the result.
Input format :
The first line of input consists of two space-separated integers, m and n, representing the
number of rows and columns in the square matrix.
The next m lines of input consist of n space-separated integers each, representing the
elements of the square matrix.
Output format :
The first line of output displays the original matrix, then print the following format:
If the input matrix is not a square matrix (m ≠ n), print "Matrix entered should be a Square
Matrix" and return.
Otherwise, transform the given matrix into its lower triangular form and print the resulting
lower triangular matrix.
Refer to the sample output for the formatting specifications.
Code constraints :
1 <= m, n <= 10
1 <= elements <= 1000
Square matrix only

22UIT304 – JAVA PROGRAMMING LABORATORY


MUTHU BHAVANI D 710723104062

AIM:-

ALGORITHM:-

22UIT304 – JAVA PROGRAMMING LABORATORY


MUTHU BHAVANI D 710723104062

PROGRAM:-

OUTPUT:-

22UIT304 – JAVA PROGRAMMING LABORATORY


MUTHU BHAVANI D 710723104062

RESULT:-

22UIT304 – JAVA PROGRAMMING LABORATORY


MUTHU BHAVANI D 710723104062

EXP NO: 2.4


SECOND LARGEST ELEMENT IN THE ARRAY
DATE:

PROBLEM STATEMENT:-
Write a program that finds the second-largest element in the array.
Input format :-
The first line of the input consists of the value of n.
The second line of input consists of an array of elements.
Output format:-
The output prints the second-largest element in the array.
Refer to the sample output for format specifications.
Code constraints :
1 <= n <= 20
1 <= arr[i] <= 1000

22UIT304 – JAVA PROGRAMMING LABORATORY


MUTHU BHAVANI D 710723104062

AIM:-

ALGORITHM:-

22UIT304 – JAVA PROGRAMMING LABORATORY


MUTHU BHAVANI D 710723104062

PROGRAM:-

OUTPUT:-

22UIT304 – JAVA PROGRAMMING LABORATORY


MUTHU BHAVANI D 710723104062

RESULT:-

22UIT304 – JAVA PROGRAMMING LABORATORY

You might also like