Featured Post

Thursday, May 11, 2017

Java program to initialise two dimensional array, reading and displaying array elements onto the screen


import java.util.Scanner;
class twodim    /* twodim.java*/
{
 public static void main(String args[])
 {
   Scanner s=new Scanner(System.in);
   int a[][]=new int[10][10];
   int i,j,r,c;
   System.out.println("enter the number of rows and columns of a matrix");
   r=s.nextInt();
   c=s.nextInt();
   System.out.println("enter the elements into the matrix");
   for(i=0;i<r;i++)
    {
     for(j=0;j<c;j++)
      {
       a[i][j]=s.nextInt(); /* reading elements into the array */
      }
    }
 
    for(i=0;i<r;i++)
     {
      System.out.println(); /* just to move the curson to next line*/
       for(j=0;j<c;j++)
       {
        System.out.print(a[i][j]+"\t"); /* displaying array elements onto the screen */
       }
     }
  }
}

OUTPUT:
D:\cjuschools>javac twodim.java
D:\cjuschools>java twodim
enter the number of rows and columns of a matrix
3
3
enter the elements into the matrix
1
2
3
4
5
6
7
8
9

1   2   3
4   5   6
7   8   9

                                                    Next

oops through java,inheritance,interface,package,super keyword, program demonstrating the use of super keywork,abstract class,static,main,awt,swings,jtab,layout, panel,applet,param,Frame, JFrame, swingutilities.invokeLater,swingutilities.invokeanwait,multithreading,multiprocesing, start(),init() paint(),adapter class,inner class,annonymous inner class,outer class,packages, friendly,  constrcutors,destructors,garbage collector,inheritance,encapusulation,abstraction, bytecode,compiler,interpreter,jdbc,jsp pages,exception handling


 
  

No comments:

Post a Comment