Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Need a quick code written (should take ~5 mins. at most): This is a sample trans

ID: 3527458 • Letter: N

Question

Need a quick code written (should take ~5 mins. at most): This is a sample transcript of what your program should do. Items in bold are user input and should not be put on the screen by your program. Enter a long string: The quick brown fox jumped over the lazy dog Enter a substring: jumped Length of your string: 44 Length of your substring: 6 Starting position of your substring in string: 20 String before your substring: The quick brown fox String after your substring: over the lazy dog Enter a position between 0 and 43: 18 The character at position 18 is x Enter a replacement string: leaped Your new string is: The quick brown fox leaped over the lazy dog Your program should work for any arbitrary string and substring. any help at all is massively appreciated...

Explanation / Answer

Following is the program. PLEASE RATE ME FIRST. The program must work. import java.io.*; import java.lang.*; class Stringop { public static void main(String args[]) throws IOException { DataInputStream dis = new DataInputStream(System.in); String s, sub_s; System.out.println("Enter a long string"); s = dis.readLine(); System.out.println("Enter a substring"); sub_s = dis.readLine(); System.out.println("Length of your string: " + s.length()); System.out.println("Length of your substring: " + sub_s.length()); sub_index = s.indexOf(sub_s) System.out.println("Starting position of your substring in string: " + sub_index); System.out.println("String before your substring: " + s.substring(0, sub_index)); System.out.println("String after your substring: " + s.substring(sub_index+sub_s.length())); System.out.println("Enter a position between 0 and " + s.length() - 1 + ": "); int pos = Integer.parseInt(dis.readLine()); System.out.println("The character at position " + pos + " is: " + s[pos]); System.out.println("Enter a replacement string"); String rep_s = dis.readLine(); String new_s = s.replace(sub_s, rep_s); System.out.println("Your new string is: " + new_s); } }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote