Skip to content

Instantly share code, notes, and snippets.

@RupGautam
Created February 23, 2017 02:25
Show Gist options
  • Select an option

  • Save RupGautam/9241ffe8448dc40751995da36db7416c to your computer and use it in GitHub Desktop.

Select an option

Save RupGautam/9241ffe8448dc40751995da36db7416c to your computer and use it in GitHub Desktop.
//Write a program to encrypt the line entered by the user. Encryption is performed
// by replacing all occurrences of the letter ‘i’ by ‘e', all occurrences of the letter ‘e’
// by the letter ‘a’, and all occurrences of the letter ‘a’ by the letter ‘i’. For example,
// if the user enters the line: The ear is big. Then the output from the program is: Tha
// air es beg. Both upper case and lower case of aforementioned letters must be
// encrypted.
import java.util.Scanner;
/**
* Copyright ${COPYRIGHT}.
*/
import java.util.regex.Pattern;
public class encryptString {
public static void main(String[] args) {
String replaced = "";
Scanner kb = new Scanner(System.in);
System.out.println("Please enter string to encrypt: ");
String str = kb.next();
//String str = "";
for (int i = 0, n = str.length(); i < n; i++) {
if (str.toLowerCase().charAt(i) == 'i') {
replaced += 'e';
} else if (str.toLowerCase().charAt(i) == 'e') {
replaced += 'a';
} else if (str.toLowerCase().charAt(i) == 'a') {
replaced += 'i';
} else {
replaced += str.charAt(i);
}
}
System.out.print(replaced);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment