Found 75 Articles for Campus Interview

Java Program to Reverse a String

AmitDiwan
Updated on 29-Mar-2022 11:08:39

708 Views

In this article, we will understand how to reverse a string. String is a datatype that contains one or more characters and is enclosed in double quotes(“ ”). Reverse string is displaying the string backwards or from right to left.Below is a demonstration of the same −Suppose our input is −The string is defined as: Java ProgramThe desired output would be −The reversed string is: margorP avaJAlgorithmStep 1 - START Step 2 - Declare two string values namely input_string and reverse_string, and a char value namely temp. Step 3 - Define the values. Step 4 - Iterating using a for-loop, ... Read More

Java Program to Replace a Character at a Specific Index

AmitDiwan
Updated on 29-Mar-2022 11:03:50

994 Views

In this article, we will understand how to replace a character at a specific index. String is a datatype that contains one or more characters and is enclosed in double quotes(“ ”).Below is a demonstration of the same −Suppose our input is −Input string: Java Programming Index: 6The desired output would be −Modified string: Java P%ogrammingAlgorithmStep 1 - START Step 2 - Declare a string value namely input_string , an integer namely index, a char value namely character, Step 3 - Define the values. Step 4 - Fetch the substring from index 0 to index value using substring(), concatenate with ... Read More

Java Program To Determine If a Given Matrix is a Sparse Matrix

AmitDiwan
Updated on 29-Mar-2022 10:17:26

208 Views

In this article, we will understand how to determine if a given Matrix is a sparse matrix. A matrix is said to be sparse matrix if most of the elements of that matrix are 0. It implies that it contains very less non-zero elements.Below is a demonstration of the same −Suppose our input is −Input matrix: 4 0 6 0 0 9 6 0 0The desired output would be −Yes, the matrix is a sparse matrixAlgorithmStep 1 - START Step 2 - Declare an integer matrix namely input_matrix Step 3 - Define the values. Step 4 - Iterate over each ... Read More

Java Program to display upper triangular matrix

AmitDiwan
Updated on 29-Mar-2022 10:12:27

600 Views

In this article, we will understand how to display an upper triangular matrix. The matrix has a row and column arrangement of its elements. A matrix with m rows and n columns can be called as m × n matrix. An upper triangular matrix is a triangular matrix with all elements below the main diagonal are 0.Below is a demonstration of the same −Suppose our input is −The matrix is defined as: 2 1 4 1 2 3 3 6 2The desired output would be −The upper triangular matrix is: 2 1 4 0 2 3 0 0 2AlgorithmStep 1 ... Read More

Java Program to Recursively Linearly Search an Element in an Array

AmitDiwan
Updated on 29-Mar-2022 10:05:33

2K+ Views

In this article, we will understand how to recursively linearly search an element in an array. Linear search is a very simple search algorithm wherein a sequential search is done for all items one by one.Below is a demonstration of the same −Suppose our input is −Input array: 14 20 35 47 50 65 72 81 90 99 Key element: 72The desired output would be −The element 72 is present at position: 6AlgorithmStep 1 - START Step 2 - Declare a string array namely input_array, two integer namely key_element and index Step 3 - Define the values. Step 4 ... Read More

Java Program To Find the Trace and Normal of a given Matrix

AmitDiwan
Updated on 29-Mar-2022 09:53:05

267 Views

In this article, we will understand how to find the trace and normal of a given matrix. The normal of a matrix is the square root of the sum of squares of all the elements of a matrix. The trace of a matrix is the sum of all the elements present in the principal diagonal (upper left to lower right).Below is a demonstration of the same −Suppose our input is −The matrix is defined as: 2 3 4 5 2 3 4 6 9The desired output would be −Trace value: 13.0 Normal value: 14.142135623730951AlgorithmStep 1 - START Step 2 - ... Read More

Java Program to Multiply to Matrix Using Multi-Dimensional Arrays

AmitDiwan
Updated on 29-Mar-2022 09:45:12

688 Views

In this article, we will understand how to multiply to matrix using multi-dimensional arrays. The matrix has a row and column arrangement of its elements. A matrix with m rows and n columns can be called as m × n matrix.Individual entries in the matrix are called element and can be represented by a[i][j] which suggests that the element a is present in the ith row and jth column.Below is a demonstration of the same −Suppose our input is −First matrix: 2 3 4 5 2 3 4 6 9 Second matrix: 1 5 3 5 6 3 8 ... Read More

Java Program to Add Two Matrix Using Multi-Dimensional Arrays

AmitDiwan
Updated on 29-Mar-2022 09:38:26

707 Views

In this article, we will understand how to add two matrix using multi-dimensional arrays. The matrix has a row and column arrangement of its elements. A matrix with m rows and n columns can be called as m × n matrix. Individual entries in the matrix are called element and can be represented by a[i][j] which suggests that the element a is present in the ith row and jth column.Below is a demonstration of the same −Suppose our input is −First matrix: 2 3 4 5 2 3 4 6 9 Second matrix: 1 5 3 5 6 3 ... Read More

Java Program to Interchange the Diagonals

AmitDiwan
Updated on 29-Mar-2022 09:32:22

132 Views

In this article, we will understand how to interchange the diagonals. The matrix has a row and column arrangement of its elements. A matrix with m rows and n columns can be called as m × n matrix.Individual entries in the matrix are called element and can be represented by a[i][j] which suggests that the element a is present in the ith row and jth column.Below is a demonstration of the same −Suppose our input is −The matrix is defined as: 4 5 6 1 2 3 7 8 9The desired output would be −The matrix after interchanging the elements: ... Read More

Java Program to Interchange Elements of First and Last in a Matrix Across Columns

AmitDiwan
Updated on 29-Mar-2022 09:23:17

420 Views

In this article, we will understand how to interchange elements of first and last in a matrix across columns. The matrix has a row and column arrangement of its elements. A matrix with m rows and n columns can be called as m × n matrix.Individual entries in the matrix are called element and can be represented by a[i][j] which suggests that the element a is present in the ith row and jth column.Below is a demonstration of the same −Suppose our input is −The matrix is defined as: 4 5 6 7 1 7 3 4 11 12 13 ... Read More

Advertisements