I want to implement a Caesar Cipher shift to increase each letter in a string by 3.
I am receiving this error:
possible loss of precision required char; found int
Here is my code so far:
import java.util.Scanner;
import java.io.*;
public class CaesarCipher
{
public static void main (String [] args) {
char[] letters = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
'w', 'x', 'y', 'z'};
char[] message = "onceuponatime".toCharArray();
char[] eMessage = new char[message.length];
char shift = 3;
//encrypting message
for(int i = 0; i <= message.length; ++i)
{
eMessage[i] = (message[i] + shift) % (char) letters.length;
System.out.println(x);
}
}
}
What causes this error? How can I implement a caesar Cipher shift to increase each letter in a string by 3?
import
statement, so you should remove them. – Gynarchy