Home Java Beginners Square Elements of Two Dimensional Array



Square Elements of Two Dimensional Array
Posted on: March 12, 2008 at 12:00 AM
This is a simple java program for implementing the two dimensional array program and its square. This session provide you the best explanation with mathematical operation.

Square Elements of Two Dimensional Array 

     

This is a simple java program for implementing the two dimensional array program and its square. This session provide you the best explanation with mathematical operation. 

Description of progarm:

We are going to display the square of two matrix. Firstly, we have to define a class "SquareMatrix".  Then we take an integer type array that contains integer type values. After this, we use two 'for' loop that denotes rows and columns of a matrix. After getting both the matrix with us we need to square both matrix. When we go to square this array then we use "square[i][j] =square[i][j] * square[i][j]". So, the output will be displayed on the screen command prompt by using the println() method.

Here is the code of this program

public class SquareMatrix {
  public static void main(String[] args) {
  int square[][]{{1,3,5},{2,4,6}};
  System.out.println("Your Original Matrix: ");
  for(int i = 0; i < 2; i++){
  for(int j = 0; j < 3; j++){
  System.out.print(square[i][j" ");
  }
  System.out.println();
  }
  for(int i = 0; i <= 1; i++) {
  for(int j = 0; j <= 2; j++) {
  square[i][j= square[i][j* square[i][j];
  
  }
  System.out.println("Matrix after changes: ");
  for(int i = 0; i < 2; i++){
  for(int j = 0; j < 3; j++){
  System.out.print(square[i][j" ");
  }
  System.out.println();
  }
  }
}

 Download this Example  

Related Tags for Square Elements of Two Dimensional Array:
javacoopmathcomidearraysessionclassstlscriptiomatrixintegermethodprintoutputgettypecolumnscreenloopdisplaycommandipviarmvaluecolumnsusingintthisoperaidaioosimplerowpromptdefinemathematicaforrowswithprogramnatvaluestoramicalcontainslanssiwsdescriptionboteilitdesnotcommaputsplusepenotesimmanfirstinnormcalasmntoutplaytrcalnjispoperationafterclesexplanationemplanmathematicalmeprosquareumnwhensspsoeeesscolatratiokisirhaimellnotemplraygodimensionandarsimxpvatttwscrssriripthavbesstatialuafhatdispdimensionalfingalumintlicaicapleplprndonomogrolo


Ask Questions?    Discuss: Square Elements of Two Dimensional Array   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.