An array defines a vector for an array that does not know the length at the beginning. It is also possible to use arraylist, hashtable, map, and hashmap.
Create an array
<Html>
<Head>
<Title> creating an array </title>
</Head>
<Body>
<H1> creating an array <%
Double accounts [];
Accounts = new double [100];
Accounts [3] = 119.63;
Out. println ("account 3 holds $" + accounts [3]);
%>
</Body>
</Html>
Two-dimensional array
<Html>
<Head>
<Title> using multidimensional arrays </title>
</Head>
<Body>
<H1> using multidimen1_arrays <%
Double accounts [] [] = new double [2] [1, 100];
Account [0] [3] = 119.63;
Account [1] [3] = 194.07;
Out. println ("savings account 3 holds $" + accounts [0] [3] + "<br> ");
Out. println ("checking account 3 holds $" + accounts [1] [3]);
%>
</Body>
</Html>
Sorts elements in an array.
<%!
Void doubler (int a [])
{
For (int I = 0; I <a. length; I ++ ){
A [I] * = 2;
}
}
%>
<%
Int array [] = {1, 2, 3, 4, 5 };
Out. println ("before the call to doubler... <br> ");
For (int I = 0; I <array. length; I ++ ){
Out. println ("array [" + I + "] =" + array [I] + "<br> ");
}
Doubler (array );
Out. println ("after the call to doubler... <br> ");
For (int I = 0; I <array. length; I ++ ){
Out. println ("array [" + I + "] =" + array [I] + "<br> ");
}
%>
Traverse arrays
While (rs2.next ())
{
Count ++;
}
String grade5name [] = new string [count];
Float mark [] = new float [count];
While (rs2.next ())
{
Grade5name [I] = rs2.getstring ("grade5name ");
Mark [I] = rs2.getfloat ("mark ");
I ++;
}
Let's take a look at this code. There are two rs. next () judgment loops.
The first while (rs2.next () loop ends and jumps out because rs has been traversed. At this time, the pointer in rs points to the end of the last record, in the second while (rs2.next (), rs2.next () must be false. Of course, the second loop will not be executed. Because the second loop cannot be executed, the corresponding data will never be obtained. If you want to traverse for the second time, you must query it again before the second while loop.
Again, I don't know why you have to use arrays. In fact, it is enough to use a loop instead of an array. It would be better to use a set.
<%
List <string> gradenamelist = new arraylist <string> ();
List <float> marklist = new arraylist <string> ();
While (rs2.next ())
{
Gradenamelist. add (rs2.getstring ("grade5name "));
Marklist. add (rs2.getfloat ("mark "));
}
For (int s = 0; s <marklist. size (); s ++)
{
%>
<Tr>
<Td width = "21"> <input type = "radio" name = "mark" value = "<% = marklist. get (s) %> "/> </td>
<Td width = "909"> <% = gradenamelist. get [s] %> </td>
</Tr>
<%
}
%>