how to create unit matrix in java of arbritary dimensions

how to create unit matrix in java of arbritary dimensions

i want to create the unit matrix of arbritary dimensions say (n*m).i m a new beginner to java.someone having the program for that? help would be appreciable.

View Answers

May 4, 2011 at 10:33 AM

import java.util.*;
class  UnitMatrix
{
    public static int[][] create(int size) {
    int[][] matrix = new int[size][size];
    for(int i = 0; i < size; i++)
      for(int j = 0; j < size; j++)
        matrix[i][j] = (i == j) ? 1 : 0;
    return matrix;
  }

    public static void main(String[] args) 
    {
        Scanner input=new Scanner(System.in);
        System.out.println("Enter size of matrix: ");
        int size=input.nextInt();
        int matrix[][]=create(size);

        for (int i=0 ; i < matrix.length ; i++)
        {     System.out.println();
            for  (int j=0 ; j < matrix[i].length ; j++){
                System.out.print(matrix[i][j]+" ");
                  }
        }

    }
}









Related Tutorials/Questions & Answers:
how to create unit matrix in java of arbritary dimensions
how to create unit matrix in java of arbritary dimensions  i want to create the unit matrix of arbritary dimensions say (n*m).i m a new beginner to java.someone having the program for that? help would be appreciable
Java create Identity matrix
Java create Identity matrix In this tutorial, you will learn how to create... elements are zeros. Here, we are going to create the unit matrix of arbitrary dimensions say (n*n). The given code accepts the size(n) of unit matrix
Advertisements
How to create a random matrix in r?
How to create a random matrix in r?  Hi, I want to create random matrix in R programming language. How to create a random matrix in r? Explain me... = ). Here is the example code of generating ram matrix with rnorm() function: >
How to Create Create Matrix of any order
Create Matrix of any order Java Program A matrix is a rectangular array of numbers.The numbers in the matrix are called its entries or its elements. A matrix with m rows and n columns is called an m-by-n matrix or m × n matrix, while m
Find sum of all the elements of matrix using Java
Find sum of all the elements of matrix using Java A matrix is a rectangular array of numbers. The numbers in the matrix are called its entries or its elements. A matrix with m rows and n columns is called m-by-n matrix or m × n matrix
how to make a matrix like datagrid in ide in java pls help
how to make a matrix like datagrid in ide in java pls help  how to make a datagrid mainly matrix in ajava standalone app
how to enter matrix data into a table of swings - Java Beginners
how to enter matrix data into a table of swings   Hi frends, I want to display a matrix data into a particular table...... Actually if the user input is 3*3 matrix and he got the matrix then it should create 3*3 table
how to find subarray from given large 2d array of arbritary dimension
how to find subarray from given large 2d array of arbritary dimension  my code is: import java.lang.*; import java.io.*; import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.List; import
Java, matrix
Java, matrix  java program to get output on the basis of users choice... of matrix.   Hello Friend, Try this:ADS_TO_REPLACE_1 import... for matrix A : "); for (int i=0 ; i < A.length ; i++) for (int j=0 ; j < A[i
Maven dependency for com.louiscad.splitties - splitties-dimensions version 3.0.0 is released. Learn to use splitties-dimensions version 3.0.0 in Maven based Java projects
( com.louiscad.splitties - splitties-dimensions version 3.0.0 ) in their Java project... - splitties-dimensions version 3.0.0 in Java projects. Follow the step by step...-dimensions in your Maven/Gradle project. Step 1: Create or use a Maven project First
Maven dependency for com.louiscad.splitties - splitties-dimensions version 3.0.0-rc03 is released. Learn to use splitties-dimensions version 3.0.0-rc03 in Maven based Java projects
( com.louiscad.splitties - splitties-dimensions version 3.0.0-rc03 ) in their Java...; com.louiscad.splitties - splitties-dimensions version 3.0.0-rc03 in Java projects... of com.louiscad.splitties - splitties-dimensions in your Maven/Gradle project. Step 1: Create
Maven dependency for com.louiscad.splitties - splitties-dimensions version 3.0.0-rc02 is released. Learn to use splitties-dimensions version 3.0.0-rc02 in Maven based Java projects
( com.louiscad.splitties - splitties-dimensions version 3.0.0-rc02 ) in their Java...; com.louiscad.splitties - splitties-dimensions version 3.0.0-rc02 in Java projects... of com.louiscad.splitties - splitties-dimensions in your Maven/Gradle project. Step 1: Create
Maven dependency for com.louiscad.splitties - splitties-dimensions version 3.0.0-rc01 is released. Learn to use splitties-dimensions version 3.0.0-rc01 in Maven based Java projects
( com.louiscad.splitties - splitties-dimensions version 3.0.0-rc01 ) in their Java...; com.louiscad.splitties - splitties-dimensions version 3.0.0-rc01 in Java projects... of com.louiscad.splitties - splitties-dimensions in your Maven/Gradle project. Step 1: Create
Maven dependency for com.louiscad.splitties - splitties-dimensions version 3.0.0-beta05 is released. Learn to use splitties-dimensions version 3.0.0-beta05 in Maven based Java projects
) in their Java project if it is based on Maven and Gradle. How to use ... to use  com.louiscad.splitties - splitties-dimensions version 3.0.0-beta05 in Java...: Create or use a Maven project First of all you have to create a new Java project
Maven dependency for com.louiscad.splitties - splitties-dimensions version 3.0.0-beta03 is released. Learn to use splitties-dimensions version 3.0.0-beta03 in Maven based Java projects
) in their Java project if it is based on Maven and Gradle. How to use ... to use  com.louiscad.splitties - splitties-dimensions version 3.0.0-beta03 in Java...: Create or use a Maven project First of all you have to create a new Java project
Maven dependency for com.louiscad.splitties - splitties-dimensions version 3.0.0-beta02 is released. Learn to use splitties-dimensions version 3.0.0-beta02 in Maven based Java projects
) in their Java project if it is based on Maven and Gradle. How to use ... to use  com.louiscad.splitties - splitties-dimensions version 3.0.0-beta02 in Java...: Create or use a Maven project First of all you have to create a new Java project
Maven dependency for com.louiscad.splitties - splitties-dimensions version 3.0.0-beta06 is released. Learn to use splitties-dimensions version 3.0.0-beta06 in Maven based Java projects
) in their Java project if it is based on Maven and Gradle. How to use ... to use  com.louiscad.splitties - splitties-dimensions version 3.0.0-beta06 in Java...: Create or use a Maven project First of all you have to create a new Java project
Maven dependency for com.louiscad.splitties - splitties-dimensions version 3.0.0-beta04 is released. Learn to use splitties-dimensions version 3.0.0-beta04 in Maven based Java projects
) in their Java project if it is based on Maven and Gradle. How to use ... to use  com.louiscad.splitties - splitties-dimensions version 3.0.0-beta04 in Java...: Create or use a Maven project First of all you have to create a new Java project
Java Transpose of a matrix
Java Transpose of a matrix In this section, you will learn how to determine the transpose of a matrix.The transpose of a matrix is formed by interchanging... to create a matrix. Then using the for loop statements, turn all the rows
how to find the eigenvalue and eigenvector of n*n matrix in java
how to find the eigenvalue and eigenvector of n*n matrix in java  I m the new beginner in java and want to find eigenvalue and eigenvector of n*n matrix.where n is vary from n=4,5,6...... pls help me that would be appreciable
Parallel multiplication matrix in java
Parallel multiplication matrix in java  hello dear I need parallel multiply matrix in java algorithm to account speed up and efficiency great wishes
matrix calculator - Java Beginners
matrix calculator  hi..... can you help me in writing source code of matrix calculator in java... i know you are the best you can do it!!! show yourself
Matrix Multiplication in Java
Matrix Multiplication in Java In this Java tutorial we will demonstrate you 'Matrix Multiplication in Java' with the help of a simple example from which you can easily learn how to write a matrix multiplication program in Java
matrix determination in java
matrix determination in java  hai
matrix adddition
matrix adddition   how to write a program matrix addition in java
how to create notepad in java
how to create notepad in java  how to create notepad in java
Matrix Addition using RMI in Java
Matrix Addition using RMI in Java  Source Code for Matrix Addition using RMI in Java
How to create a class in java
How to create a class in java  I am a beginner in programming and tried to learn how to do programming in Java. Friends please explain how can I create a class in Java
How to create charts in Java?
How to create charts in Java?  Is there any example of creating charts and graphs in Java? thanks   Hi, check the tutorial: Chart & Graphs Tutorials in Java Thanks
How to Create Keyboard in JAVA
How to Create Keyboard in JAVA  please help me to create On-Screen Keyboard with java and please give me an another idia to make it ..............iam waiting for your help ,think u so much
how to create interfaces in java
how to create interfaces in java  HI, Here is my code public interface validateInfo { public void validate(String empcode, String password); } class updateInfo implements validateInfo { public void update() { //code
Matrix - Java Beginners
Matrix  give me the Matrix program   Hi friend, Code for Matrix Example in Java class MatrixExample{ public static void main...(" ]"); } System.out.println(); } } For more information on java visit to : http
Dividing of two Matrix in Java
;Here you will learn how to use two matrix array for developing Java program.  The java two dimensional array program is operate the two matrix. Now we... Dividing of two Matrix in Java   
Setting the Dimensions of an Item in a JList Component in Java
Setting the Dimensions of an Item in a JList Component in Java..., you will learn about setting the dimensions of the List component in java. A list can have multiple data or items. Here, you will know how to set data or items
Java Multi Dimensions Array - Java Tutorials
.style1 { text-align: center; } Multidimensional Arrays in Java In java, the grouping of same type of elements for storing under the same name... below the example to provide you an idea-how array works?ADS_TO_REPLACE_1
how to change file from .txt to .mat(matrix)
how to change file from .txt to .mat(matrix)  i have a big file.txt and i want to change this file to file.mat(matrix) ...this is in windows not on any os ..thx if u answering quickly please
code for multiplication of matrix in java using methods
code for multiplication of matrix in java using methods  code for multiplication of matrix in java using methods
ModuleNotFoundError: No module named 'dimensions'
'dimensions' How to remove the ModuleNotFoundError: No module named 'dimensions' error? Thanks   Hi, In your python environment you...ModuleNotFoundError: No module named 'dimensions'  Hi, My Python
ModuleNotFoundError: No module named 'dimensions'
'dimensions' How to remove the ModuleNotFoundError: No module named 'dimensions' error? Thanks   Hi, In your python environment you...ModuleNotFoundError: No module named 'dimensions'  Hi, My Python
how to create reports in swing java?
how to create reports in swing java?  how to create reports in swing java
Maven dependency for net.javacrumbs.json-unit - json-unit version 2.23.0 is released. Learn to use json-unit version 2.23.0 in Maven based Java projects
version 2.23.0 ) in their Java project if it is based on Maven and Gradle. How...? Steps to use  net.javacrumbs.json-unit - json-unit version 2.23.0 in Java... of net.javacrumbs.json-unit - json-unit in your Maven/Gradle project. Step 1: Create or use
Maven dependency for net.javacrumbs.json-unit - json-unit version 2.26.0 is released. Learn to use json-unit version 2.26.0 in Maven based Java projects
version 2.26.0 ) in their Java project if it is based on Maven and Gradle. How...? Steps to use  net.javacrumbs.json-unit - json-unit version 2.26.0 in Java... of net.javacrumbs.json-unit - json-unit in your Maven/Gradle project. Step 1: Create or use
Maven dependency for net.javacrumbs.json-unit - json-unit version 2.29.0 is released. Learn to use json-unit version 2.29.0 in Maven based Java projects
version 2.29.0 ) in their Java project if it is based on Maven and Gradle. How...? Steps to use  net.javacrumbs.json-unit - json-unit version 2.29.0 in Java... of net.javacrumbs.json-unit - json-unit in your Maven/Gradle project. Step 1: Create or use
Maven dependency for net.javacrumbs.json-unit - json-unit version 2.35.0 is released. Learn to use json-unit version 2.35.0 in Maven based Java projects
version 2.35.0 ) in their Java project if it is based on Maven and Gradle. How...? Steps to use  net.javacrumbs.json-unit - json-unit version 2.35.0 in Java... of net.javacrumbs.json-unit - json-unit in your Maven/Gradle project. Step 1: Create or use
Maven dependency for net.javacrumbs.json-unit - json-unit version 2.31.0 is released. Learn to use json-unit version 2.31.0 in Maven based Java projects
version 2.31.0 ) in their Java project if it is based on Maven and Gradle. How...? Steps to use  net.javacrumbs.json-unit - json-unit version 2.31.0 in Java... of net.javacrumbs.json-unit - json-unit in your Maven/Gradle project. Step 1: Create or use
Maven dependency for net.javacrumbs.json-unit - json-unit version 2.29.0 is released. Learn to use json-unit version 2.29.0 in Maven based Java projects
version 2.29.0 ) in their Java project if it is based on Maven and Gradle. How...? Steps to use  net.javacrumbs.json-unit - json-unit version 2.29.0 in Java... of net.javacrumbs.json-unit - json-unit in your Maven/Gradle project. Step 1: Create or use
Maven dependency for net.javacrumbs.json-unit - json-unit version 1.8.0 is released. Learn to use json-unit version 1.8.0 in Maven based Java projects
version 1.8.0 ) in their Java project if it is based on Maven and Gradle. How... to use  net.javacrumbs.json-unit - json-unit version 1.8.0 in Java projects... of net.javacrumbs.json-unit - json-unit in your Maven/Gradle project. Step 1: Create or use
Maven dependency for net.oneandone.ioc-unit - ioc-unit version 2.0.45 is released. Learn to use ioc-unit version 2.0.45 in Maven based Java projects
2.0.45 ) in their Java project if it is based on Maven and Gradle. How to use ...; net.oneandone.ioc-unit - ioc-unit version 2.0.45 in Java projects. Follow... - ioc-unit in your Maven/Gradle project. Step 1: Create or use a Maven project
Maven dependency for net.javacrumbs.json-unit - json-unit version 2.21.0 is released. Learn to use json-unit version 2.21.0 in Maven based Java projects
version 2.21.0 ) in their Java project if it is based on Maven and Gradle. How...? Steps to use  net.javacrumbs.json-unit - json-unit version 2.21.0 in Java... of net.javacrumbs.json-unit - json-unit in your Maven/Gradle project. Step 1: Create or use
Maven dependency for net.javacrumbs.json-unit - json-unit version 2.18.1 is released. Learn to use json-unit version 2.18.1 in Maven based Java projects
version 2.18.1 ) in their Java project if it is based on Maven and Gradle. How...? Steps to use  net.javacrumbs.json-unit - json-unit version 2.18.1 in Java... of net.javacrumbs.json-unit - json-unit in your Maven/Gradle project. Step 1: Create or use

Ads