Answer to Question #239024 in Java | JSP | JSF for guru

Question #239024

Java considers the String data type as non-primitive, because it contains a sequence of characters and hence there is a predefined class called String dedicated to String processing. The String class has a lot of functions and continues to grow. See https://www.tutorialspoint.com/java/java_strings.htm for more on strings. Your task is to then create a java program that when give a sentence will replace the first occurrence of NUST with Namibia University of Science and Technology.

Sample run 1: Enter a sentence: Welcome to my NUST.

Output: Welcome to my Namibia University of Science and Technology.

Sample run 2: Enter a sentence: The nust is a great institution of high learning.

Output: The Namibia University of Science and Technology is a great institution of high learning.


1
Expert's answer
2021-09-18T17:27:51-0400
import java.util.Scanner;
public class Main
{
	public static void main(String[] args) {
	    Scanner in=new Scanner(System.in);
		String org_str=in.nextLine();  
		String rep_str="Namibia University of Science and Technology";
        String str=org_str.replace("NUST",rep_str); 
        System.out.println(str); 
	}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS