I'm in an intro to Java class right now and we were just asked to create a encryption program that would take an argument and return it as an encrypted message.
What I wanted to do was take two command line arguments. The fist one would be the word or message that would be encrypted, and the second would be the integer value used to determine the encryption.
It would take the first argument and convert it to a character array and it would take the second argument and change the string to an integer.
It would then have a loop that would continue to loop until it had looped through the whole character array once. Each character would, in theory, be assigned a new encrypted character by adding a certain value to it and reassigned it in the array.
After every character has been encrypted then the program would print out the encrypted string.
So far this is what I have:
public class cypherCaesar{ public static void main(String args[]){ String message = args[0]; char arr[] = message.toCharArray(); String cypher = args[1]; int cypherVal = Integer.parseInt(cypher); int c = 0; for (int i = 0; i < arr.length; i++) { arr[(0 + c)] = arr[(0 + c)] + (cypherVal%26); c++; } String encryptedMessage = new String(arr); System.out.println(encryptedMessage); }}
And this is the error I get back when I try to compile it:
cypherCaesar.java:11: error: possible loss of precision arr[(0 + c)] = arr[(0 + c)] + (k%26); ^ required: char found: int1 error
I know it's probably something really small that I'm looking over. Does anyone know how I can fix this?