|
-
Nov 13th, 2002, 08:31 AM
#1
Thread Starter
New Member
Copy elements of an array
I have 4 arrays (a,b,c,d). If the comparison between elements of c & a =, d should be copied with the value of b. follow?
the problem I have is that it doesn't copy the values from array b to d. I cannot figure y. Can Sb. help me??
This is my code: {
String[] words = {"before", "to", "great", "later", "you",
"very", "see", "message", "one", "smile"};
String[] codeW = {"b4", "2", "gr8", "l8r", "u", "V.", "c",
"Mssg.", "1", " "};
String[] codedArray;
String message = "";
{
//------------ Ask for input of message in plain English
message = JOptionPane.showInputDialog( "Please enter message" );
//------------ Tokenizes input, declares array and fill's with tokens
StringTokenizer stock = new StringTokenizer(message);
int count1 = stock.countTokens();
String [] messArray = new String[count1];
for (int i=0; i< count1;i++)
messArray[i] = stock.nextToken();
//------------ Creates new array to hold Coded Message
codedArray = new String[count1];
//------------ Compares tokens against words to be coded (array [words]
for (int n = 0; n < words.length; n++)
{
for (int x = 0; x < messArray.length; x++)
{
if (messArray[x].equalsIgnoreCase(words[n]))
{
System.arraycopy(codeW, n, codedArray, x, 1);
System.out.println(codedArray[x]);//To check values of array
}
else
{
System.arraycopy(messArray, x, codedArray, x, 1);
}
}
}
for (int y = 0; y < codedArray.length; y++)
JOptionPane.showMessageDialog(null,"Coded Message\n" + codedArray[y]);
System.exit(0);
}
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|