I am making a program that encrypts a string by increasing the value for each character by 5. Ex) A=F, B=G etc. Here is what I have come up with so far:
public class CharArray
{
public static void main(String[] args)
{
String str = "This sentence will be encrypted";
char[] charArray = str.toCharArray();
int pos=0;
while (pos<str.length())
{
char x = (charArray[pos]);
System.out.print((x+5) + " ");
//System.out.print(charArray[x]); This causes an exception error
pos++;
}
}
}
But the output for this is:
89 109 110 120 37 120 106 115 121 106 115 104 106 37 124 110 113 113 37 103 106 37 106 115 104 119 126 117 121 106 105