In: Computer Science
Write a java code to ask the user for a string, and assuming the user enters a string containing character "a", your java program must convert all "a" to "b" in the string so for example if user types : "AMAZON" , your program must convert it to "BMBZON"
the driver program must ask :
enter a string containing "a" or "A"
--------- (user enters string)
then it should say;
HERE IS YOUR NEW STRING
---------- (string with all a's converted to b.)
important : all a's should be b and even for capital letters (i.e. A to B).
Java Code
import java.util.*;
public class Main
{
public static void main(String[] args)
{
Scanner input= new Scanner(System.in);
System.out.println("enter a string containing \"a\" or \"A\"");
String str = input.nextLine();
String strupper = str.replace('A', 'B');// Replace all the capital letters 'A' characters with Uppercase 'B' characters.
String resultstring=strupper.replace('a', 'b');// Replace all the lowercase letters 'a' characters with Uppercase 'b' characters.
System.out.println("HERE IS YOUR NEW STRING ");
System.out.println(resultstring);
}
}
Output