Computer Science, asked by blacktan, 7 hours ago

Write a program to accept a string, convert it to lower case and replace each character by its next adjacent character. (The alpabhet 'z' and 'Z' will be replaced by 'a' and 'A' respectively). Sample input: zebra Sample output: afesb​

Answers

Answered by BrainlyProgrammer
4

Answer:

//The following cødes have been written in java

import java.util.*;

class abc{

public static void main(String ar[]) {

Scanner sc=new Scanner(System.in) ;

System.out.println("Enter a string ") ;

String s=sc.nextLine().toLowerCase();

String p="";

for(int I=0;I<s.length() ;I++) {

if(s.charAt(I)!=' ')

p+=(char)(s.charAt(I)+1) ;

else

p+=" ";

}

System.out.println("New String:"+p) ;

}

}

Logic:-

  • Get the ascii códe of character
  • Add one to it and convert it back to the character by Type Casting it

•••Required Output Attached

Attachments:
Similar questions