
read a sentence and encrypt with stratergy of replacing character with immediate preeceding character

Hi Friend,
Try the following code:
import java.util.*;
class Encrypt{
public static void shiftLeft(char[] array, int amount) {
for (int j = 0; j < amount; j++) {
char a = array[0];
int i;
for (i = 0; i < array.length - 1; i++)
array[i] = array[i + 1];
array[i] = a;
}
}
public static void printArray(char[] array) {
for (int x = 0; x < array.length; x++) {
System.out.print(array[x]);
}
System.out.println();
}
public static void main(String[] args)
{
Scanner input=new Scanner(System.in);
System.out.print("Enter String: ");
String str=input.nextLine();
char ch[]=str.toCharArray();
shiftLeft(ch, 1);
System.out.print("String is Encrypted: ");
printArray(ch);
}
}
Thanks
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.