I have a code to print a random number position for each letter and each letter is printed in the generated random number position in a grid and rest of the grid is filled with characters other than the initial letters for which positions were generated. Now i need to determine the intersection of random number pairs. For example my string is abcd, which is split into ab and cd. And for a, the random number position is generated say 1 2 and for b the position is 2 3 , the intersection must be 1 2 i.e row position of the first letter and column position of the second letter. However I dont know how to go about finding the intersection position. Here's my code:
<%@page contentType="text/html" pageEncoding="UTF-8" %>
<%@page import="java.sql.*"%>
<%@page import="java.util.*"%>
<%@page import="java.lang.*"%>
<%
String vlemail=request.getParameter("vlemail");
try
{
String str="jdbc:mysql://localhost:3306/licet";
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con=null;
con=DriverManager.getConnection(str,"root","");
Statement st=con.createStatement();
// st.executeQuery("select pwd from utable where email('?') values('lemail')");
ResultSet rs =st.executeQuery("select Password from record where email='"+vlemail+"'");
while(rs.next())
{
String r=rs.getString("Password");
int matrix_length = 7;
int a[][]=new int[matrix_length+1][matrix_length+1];
char table[][] = new char [matrix_length][matrix_length];
String allcharacters ="abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()_=+-";
Random rand=new Random();
for(int k=0; k < r.length(); k++){
allcharacters = allcharacters.replace(r.substring(k,k+1),"");
}
//out.println(allcharacters);
String pair[] = new String[r.length()/2];
for( int i = 0; i <pair.length; i++ )
{
pair[i] = r.substring(i*2,(i*2)+2);
out.println(pair[i]);
}
int positions [][][];
positions = new int[pair.length][r.length()/2][2];
for(int j = 0; j < pair.length; j++)
{
int prand1 = matrix_length,prand2 = matrix_length;
for(int i = 0; i < pair[j].length();i++)
{
int rand1=matrix_length, rand2=matrix_length;
do
{
rand1=Math.abs(rand.nextInt());
rand2=Math.abs(rand.nextInt());
rand1%=matrix_length;
rand2%=matrix_length;
}while(((rand1==prand1)||(rand2==prand2)||(a[rand1][rand2]==1)));
positions[j][i][0] = rand1;
positions[j][i][1] = rand2;
out.println(r.charAt(i+(j*pair[0].length()))+" " + positions[j][i][0]+" " + positions[j][i][1]);
if(i==0){
prand1=rand1;
prand2=rand2;
}else{
prand1=rand1;
}
a[rand1][rand2] = 1;
table[rand1][rand2] = r.charAt(i+(j*pair[0].length()));
}
a[prand2][prand1] = 1;
table[prand2][prand1] = allcharacters.charAt((char)(Math.abs(rand.nextInt())%allcharacters.length())) ;
}
out.println("<br/>");
out.println("<table border=2 cellspacing=0 cellpadding=0>");
for(int j = 0; j < matrix_length; j++){
out.println("<tr>");
for(int k = 0; k < matrix_length; k++){
if(!(a[j][k] == 1)){
table[j][k] = allcharacters.charAt((char)(Math.abs(rand.nextInt())%allcharacters.length())) ;
}
out.println("<td>"+String.valueOf(table[j][k]) +"</td>");
}
out.println("</tr>");
out.println("<br/>");
}
out.println("<table>");
}
//out.println("Retrieved" );
}
catch(Exception e)
{
out.println(e);
out.println("Not retrieved");
}
%>
Aucun commentaire:
Enregistrer un commentaire