Found 2617 Articles for Java

Java Program to Compute the Sum of Diagonals of a Matrix

AmitDiwan
Updated on 18-Jun-2024 17:51:56

8K+ Views

In this article, we will understand how to compute the sum of diagonals of a matrix. The matrix has a row and column arrangement of its elements. The principal diagonal is a diagonal in a square matrix that goes from the upper left corner to the lower right corner.The secondary diagonal is a diagonal of a square matrix that goes from the lower left corner to the upper right corner.Below is a demonstration of the same −Suppose our input is −The input matrix: 4 5 6 7 1 7 3 4 11 12 13 14 23 24 25 50The desired ... Read More

Java Program to Rotate Matrix Elements

AmitDiwan
Updated on 29-Mar-2022 09:04:31

537 Views

In this article, we will understand how to rotate matrix elements. A matrix is representation of the elements in rows and columns. Matrix rotation is shifting the position of each element of the matrix by 1 position towards it’s right or left.Below is a demonstration of the same −Suppose our input is −The matrix is defined as 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16The desired output would be −The matrix after one rotation: 5 1 2 3 9 10 6 4 13 11 7 8 14 15 16 12AlgorithmStep 1 - ... Read More

Java Program to Print Boundary Elements of a Matrix

AmitDiwan
Updated on 30-Mar-2022 08:01:35

2K+ Views

In this article, we will understand how to print boundary elements of a matrix. A matrix is representation of the elements in rows and columns. Boundary elements are those elements which are not surrounded by elements on all four directions. For example, the elements in the first row, first column, last row and last column.Below is a demonstration of the same −Suppose our input is −The input matrix: 9 8 9 8 8 7 8 7 7 6 7 6 6 5 6 5The desired output would be −The border elements of the matrix is: 9 8 9 8 8 ... Read More

Java Program to Calculate Standard Deviation

AmitDiwan
Updated on 09-Jul-2024 17:52:30

2K+ Views

In this article, we will understand how to calculate standard deviation. The standard deviation is the measure of how spread-out numbers are. The symbol of standard deviation is sigma( σ ). It is the square root of variance. Standard deviation is computed using the formula square root of ∑(Xi - ų)2 / N where Xi is the element of the array, ų is mean of the elements of the array, N is the number of elements, ∑ is the sum of the each element. Problem Statement Given a program in Java to calculate the standard deviation of a given ... Read More

Java Program to Print X Star Pattern

AmitDiwan
Updated on 25-Jun-2024 15:53:54

8K+ Views

In this article, we will understand how to print X star pattern. The pattern is formed by using multiple for-loops and print statements. Below is a demonstration of the same: − Input Suppose our input is − Enter the number : 8 Output The desired output would be − The X star pattern : X                 X  X               X   X             X    X           X     X         X     ... Read More

Java Program to Print Half Diamond Star Pattern

AmitDiwan
Updated on 28-Feb-2022 05:38:26

892 Views

In this article, we will understand how to print half diamond star pattern. The pattern is formed by using multiple for-loops and print statements.Below is a demonstration of the same −InputSuppose our input is −Enter the number of rows : 8OutputThe desired output would be −The half diamond pattern : * ** *** **** ***** ****** ******* ******** ******* ****** ***** **** *** ** *AlgorithmStep 1 - START Step 2 - Declare three integer values namely i, j and my_input Step 3 - Read the required values from the user/ define the values Step 4 - We iterate through two ... Read More

Java Program to Print Hollow Right Triangle Star Pattern

AmitDiwan
Updated on 25-Feb-2022 13:33:52

4K+ Views

In this article, we will understand how to print hollow right triangle star pattern. The pattern is formed by using multiple for-loops and print statements. For the pyramid at the first line it will print one star, and at the last line it will print n number of stars. For other lines it will print exactly two stars at the start and end of the line, and there will be some blank spaces between these two starts.Below is a demonstration of the same −InputSuppose our input is −Enter the size : 8OutputThe desired output would be −The hollow pyramid triangle ... Read More

Java Program to Print Inverted Star Pattern

AmitDiwan
Updated on 25-Feb-2022 13:09:48

1K+ Views

In this article, we will understand how to print inverted star pattern. The pattern is formed by using multiple for-loops and print statements.Below is a demonstration of the same −InputSuppose our input is −Enter the size : 8OutputThe desired output would be −The inverted star pattern *************** ************* *********** ********* ******* ***** *** *AlgorithmStep 1 - START Step 2 - Declare four integer values namely i, j, k and my_input. Step 3 ... Read More

Java Program to Print 8 Star Pattern

AmitDiwan
Updated on 25-Feb-2022 13:04:57

615 Views

In this article, we will understand how to print 8-star pattern. The pattern is formed by using multiple for-loops and print statements.Below is a demonstration of the same −InputSuppose our input is −Enter the number : 8OutputThe desired output would be −The 8 pattern : ****** *    * *   * * * * * * * * * ****** * * * * * * * * * * * ... Read More

Java Program to Create Pyramid and Pattern

AmitDiwan
Updated on 10-Aug-2023 13:03:03

466 Views

If someone wants to build a strong foundation in Java programming language. Then, it is necessary to understand the working of loops. Also, solving the pyramid pattern problems is the best way to enhance the fundamentals of Java as it includes extensive use of the for and while loops. This article aims to provide a few Java programs to print pyramid patterns with the help of different types of loops available in Java. Java Program to Create Pyramid Patterns We are going to print the following Pyramid Patterns through Java programs − Inverted Star Pyramid Star Pyramid Numeric Pyramid ... Read More

Advertisements