Search This Blog

Sunday, 24 August 2014

21. JSP Program to Sort Two Dimensional Array.

<!-- 21. JSP Program to sort 2D array. -->
<html>
<head>
</head>

<body bgcolor="beige">
<h2>TWO - DIMENSIONAL ARRAY SORTING</h2>
<h2><font color="blue">
<%
    int A[][]={ {12,5,14},{3,2,66},{28,45,4},{23,6,16}};
    int  t=0;
    int row=A.length;
    int col=A[0].length;
   
    out.println("The Given 2D Array:<BR>");

%>
   
    <table border=3 height=200 width=200>
<%
    for(int i=0;i<row;i++)
    {
%>
         
        <tr align=center >
<%
        for(int j=0;j<col;j++)
        {
%>
            <td><%=A[i][j]%></td>
<%
        }
%>
        </tr>
<%
    }
%>
    </table>
<%  

      
            for(int x=0;x<row;x++)
            {
                for(int y=0;y<col;y++)
                {
                    for(int i=0;i<row;i++)
                    {
                        for(int j=0;j<col;j++)
                        {
                            if(A[i][j]>A[x][y])
                            {
                                t=A[x][y];
                                A[x][y]=A[i][j];
                                A[i][j]=t;
                            }
                        }
                    }
                }
            }

        out.println("The Sorted 2D Array:<BR>");
%>
        <table border=3 height=200 width=200>
<%
    for(int i=0;i<row;i++)
    {
%>
         
        <tr align=center >
<%
        for(int j=0;j<col;j++)
        {
%>
            <td><%=A[i][j]%></td>
<%
        }
%>
        </tr>
<%
    }
%>
    </table>
  
    </font></h2>
    <body>
</html>

No comments :

Post a Comment

FREE Hit Counters