import java.util.*;
import java.util.Random;
import java.lang.*;
public class testing1
{
public static void main(String[] args)
{
String pass = new String("ENTER THE HAMLET HAM TO BE OR NOT TO BE THAT IS THE QUESTION WHETHER TIS NOBLER IN THE MIND TO SUFFER THE SLINGS AND ARROWS OF OUTRAGEOUS FORTUNE OR TO TAKE ARMS AGAINST A SEA OF TROUBLES AND BY OPPOSING END");
int[] passnum = new int[pass.length()];
for(int i=0; i<pass.length(); i++)
{
if(pass.charAt(i)>64 && pass.charAt(i)<91){
passnum[i] = pass.charAt(i)-65;}
else{
passnum[i] = 26;}
//System.out.println(passnum[i]);
}
int table[][] = new int [27][27];
for(int row=0; row<table.length; row++){
for(int column=0; column<table[row].length; column++){
table[row][column] = 0;
}
}
for(int i=0; i<passnum.length-2; i++){
table[passnum[i]][passnum[i+1]]++;}
for(int row=0; row<table.length; row++){
for(int column=0; column<table[row].length; column++){
System.out.print(table[row][column]+"\t");
}
System.out.println();
}
int[] f = new int[27];
for(int i=0; i<f.length; i++){
f[i] = i;}
int[] fstar = new int[27];
for(int i=0; i<fstar.length; i++){
fstar[i] = f[i];}
for(int s=0; s<200; s++){
Random r = new Random();
int n = 27;
int temp;
int i=r.nextInt(n+1);
int j= r.nextInt(n+1);
temp = fstar[i];
fstar[i] = fstar[j];
fstar[j] = temp;
for(int k=0; k<passnum.length; k++){
int plf = passnum[k];
int plfstar = passnum[k];
for(int m=0; m<passnum.length-2; m++){
plf = plf * table[f[passnum[m]]][f[passnum[m+1]]];}
for(int l=0; n<passnum.length-2; l++){
plfstar = plfstar * table[f[passnum[l]]][f[passnum[l+1]]];}
if(plfstar > plf){
f[i] = fstar[i];break;}
else{
Random rand = new Random();
int c = 2;
int coin = rand.nextInt(c+1);
if(coin < (plfstar/plf)){
f[i] = fstar[i];}
else{
fstar[i] = f[i];}
}
}
}
krip_101
-3
Newbie Poster
Recommended Answers
Jump to PostHelp with what?
How to use code tags maybe? Select your code and click the button on the editor that says [code]
How to properly post a question? Use a descriptive title, not just "help" or "urgent" (trust me, it's not urgent to anyone else). Describe the …
Jump to PostAppears to be something related with encoding... There is missing two parenthesis at the end. Some array exceeded the length. I did correct indentation with Eclipse, looks better now.
Jump to PostOkay, now there's something to work with.
To read from a file, you need to get the name of the file - you want to get that from the user at the command line. Then you need to open the file and read in its contents. Then you need to …
All 12 Replies
Ezzaral
2,714
Posting Sage
Team Colleague
Featured Poster
martin5211
37
Posting Whiz in Training
krip_101
-3
Newbie Poster
Eric Cute
33
Posting Whiz in Training
krip_101
-3
Newbie Poster
jon.kiparsky
326
Posting Virtuoso
krip_101
-3
Newbie Poster
jon.kiparsky
326
Posting Virtuoso
krip_101
-3
Newbie Poster
jon.kiparsky
326
Posting Virtuoso
krip_101
-3
Newbie Poster
Ezzaral
commented:
Lame.
-3
krip_101
-3
Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.