Your task is to then create a java program that when given an acronym with its meaning plus some sentence, the program replaces the first occurrence of the acronym in the sentence with its meaning.
Sample run 1:
Enter an acronym and its meaning (separated by spaces): NUST Namibia University of Science and Technology
Enter a sentence: Welcome to my NUST. Output: Welcome to my Namibia University of Science and Technology.
Source code
import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
Scanner in=new Scanner(System.in);
String s;
System.out.print("Enter a sentence: ");
s=in.nextLine();
String s2="Namibia University of Science and Technology";
String s3=s.replace("NUST",s2);
System.out.println(s3);
}
}
Output
Comments
Leave a comment