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 sense.
charArray is taken from JTextField.
Therefore, the code should do something like this.
- Receives a message and flips every 2 characters. That is, the 1st and 2nd characters switch, and the 3rd and 4th switches, etc.
- For example, "You cannot read my message!" after encryption will be "oY uac'n terdam yemssga! e";
charArray is a message that says: "You cannot read my message!" flipArray will carry a message that says "oY uac'n terdam yemssga! e"
How to write a loop that puts it in such a way 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 JTextField.
I do this in NetBeans IDE 6.5.1.