So the question asked is: To change the characters of a string with 3 characters ahead of them so lets say the string is "AB cd" it would be changed to: "DE fg". I am not good at programing but I have tried my best and come up with this:
import java.util.*;
public class encrypt{
public static void main(String[] args){
Scanner reader = new Scanner(System.in);
System.out.println("Enter a message to encrypt: ");
String message = reader.nextLine();
List<Character> Lowercase = Arrays.asList('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');
List<Character> Uppercase = Arrays.asList('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');
for ( int i = 0; i < message.length(); i++ ) {
char c = message.charAt( i );
if( c == ' '){
continue;
}
else if (c != ' '){
for ( int i = 0; i < Lowercase.size(); i++ ) {
char b = Lowercase.indexOf(i);
if(c == b){
message.charAt(i)=Lowercase.indexOf(i+3);
}
}
}
for ( int i = 0; i < Uppercase.size(); i++ ) {
char j = Uppercase.indexOf(i);
if(c == j){
message.charAt(i)=Uppercase.indexOf(i+3);
}
}
}
}
}
I have been getting errors like :
Problem1.java:20: error: variable i is already defined in method main(String[])
for ( int i = 0; i < Lowercase.size(); i++ ) {
^
Problem1.java:21: error: possible loss of precision
char b = Lowercase.indexOf(i);
^
required: char
found: int
Problem1.java:23: error: unexpected type
message.charAt(i)=Lowercase.indexOf(i+3);
^
required: variable
found: value
Problem1.java:27: error: variable i is already defined in method main(String[])
any help would be appreciated :) thanks.