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]+" ");
                  }
        }

    }
}

Ads









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 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
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-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-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
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-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-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 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
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
how to create notepad in java
how to create notepad in java  how to create notepad 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
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
how to create reports in swing java?
how to create reports in swing java?  how to create reports in swing java
How to create first program in Java?
How to create first program in Java?  Hi, I am new in Java programming. Tell me How to create first program in Java? Thanks   Hi, Read more at First Java Program. Thanks
How to create and use Array in Java?
How to create and use Array in Java?  Hi, How to create and use Array in Java? Write program to construct and use the array. Thanks   Hi... can read complete example at Array in Java. Thanks
How to create first Java Program?
How to create first Java Program?  Hi, I am beginner and I want to write first Java program. How I can setup my machine and write first Java program... and run first Java program: Create program in Note pad: Step 1: Open
how create package of this java code
how create package of this java code  Hi,i have email code in java which is working fine with out making package but when i want to make package of this code its stop working.Its showing exception while I execute it.I have to use
how create package of this java code
how create package of this java code  Hi,i have email code in java which is working fine with out making package but when i want to make package of this code its stop working.Its showing exception while I execute it.I have to use
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 adddition
matrix adddition   how to write a program matrix addition in java
Matrix Addition using RMI in Java
Matrix Addition using RMI in Java  Source Code for Matrix Addition using RMI in Java
matrix determination in java
matrix determination in java  hai
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
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

Ads