In: Computer Science
import java.util.Scanner;
class Main
{
public static void main (String[] args)
{
// Part 1
char[] letters = {'a', 'e', 'l', 'o', 's', 't'};
char[] symbols = {'@', '3', '1', '0', '$', '7'};
// Part 2
Scanner sc = new Scanner(System.in);
System.out.println("Enter sentence in lower case");
String str = sc.nextLine();
str = str.toLowerCase();
// Part 3
char arr[] = str.toCharArray();
// Part 4
String new_str = "";
int flag=0;
for(int i=0;i<arr.length;i++){
flag=0;
for(int j=0;j<letters.length;j++){
if(arr[i]==letters[j]){
new_str+=symbols[j];
flag=1;
break;
}
}
if(flag==0)
new_str+=arr[i];
}
System.out.println(new_str);
// Part 5
char array[] = str.toCharArray();
// Part 6
System.out.print("Enter a number for shifting the text: ");
int shift = sc.nextInt();
// Part 7
char tempstr;
String finalstr="";
for(int i=0;i<array.length;i++){
if(array[i]!= ' '){
int combined = array[i] + shift;
int element = combined-97;
element = element%26;
combined = element+97;
System.out.println(array[i]);
System.out.println(combined);
System.out.println((char) combined);
tempstr = (char)combined;
}
else
tempstr = ' ';
finalstr += tempstr;
}
// Part 8
System.out.println(finalstr);
}
}
NOTE: The above code is in Java. Please refer to the attached screenshots for code indentation and sample I/O.
SAMPLE I/O: