accept a string and convert it to uppercase and replace each alphabet with the previous alphabet (i.e., Z should be replaced by Y and so on…..) and display. If the character is A then replace it by Z and display
Define a class to accept a string and convert it to uppercase and replace each alphabet with
the previous alphabet (i.e., Z should be replaced by Y and so on…..) and display. If the
character is A then replace it by Z and display. Other characters like digits, symbols
display as it is without any changes.
Sample Input: INTELLIGENCE
Sample Output: HMSDKKHFDMBD
import java.util.;
class String_P2
{
public static void main(String[]args)
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter a string");
String str=sc.nextLine();/** stores a word/sentence/
str=str.toUpperCase();
for(int i=0;i<str.length();i++)
{
char c=str.charAt(i);/** stores a character*/
if(c=='A')
System.out.print("Z");
else if(c>='B' & c<='Z')
System.out.print(--c);
else
System.out.print(c);
}
}
}
FOR CODE ,
CLICK : https://onecompiler.com/java/3y4fb2z6d (TO FIND OUTPUT)