String input = txtInput.getText();
char[] charArray = input.toCharArray();
char[] flipArray = null;
System.out.println(charArray.length);
for (int i = 0; i < charArray.length ; i++) {
System.out.println(charArray[i]);
sorry if the code doesn't make much sense.
charArray is taken from a JTextField .
So the code should do something like this.
- Takes in a message and flip every 2 characters. That is, the 1st and 2nd characters are switched and the 3rd and 4th are switched etc;
- For example, “You can't read my message!” will be “oY uac'n terdam yemssga!e” after encryption;
charArray would be the Message that says “You can't read my message!” flipArray would be carrying the message that says “oY uac'n terdam yemssga!e”
How do I write a loop that puts it in such that...
charArray[0] = flipArray[1]
charArray[1] = flipArray[0]
charArray[2] = flipArray[3]
charArray[3] = flipArray[2]
charArray[4] = flipArray[5]
charArray[5] = flipArray[4]
The value of charArray is taken from a JTextField
.
I'm doing this on NetBeans IDE 6.5.1.