1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Marrrta [24]
2 years ago
12

Your goal is to write a JAVA program that will ask the user for a long string and then a substring of that long string. The prog

ram then will report information on the long string and the substring. Finally it will prompt the user for a replacement string and show what the long string would be with the substring replaced by the replacement string. Each of the lines below can be produced by using one or more String methods - look to the String method slides on the course website to help you with this project.
A few sample transcripts of your code at work are below - remember that your code should end with a newline as in the textbook examples and should produce these transcripts exactly if given the same input. Portions in bold indicate where the user has input a value.
One run of your program might look like this:
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: 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
Goodbye!
A second run with different user input might look like this:
Enter a long string: Friends, Romans, countrymen, lend me your ears
Enter a substring: try
Length of your string: 46
Length of your substring: 3
Starting position of your substring: 21
String before your substring: Friends, Romans, coun
String after your substring: men, lend me your ears
Enter a position between 0 and 45: 21
The character at position 21 is t
Enter a replacement string: catch
Your new string is: Friends, Romans, councatchmen, lend me your ears
Goodbye!
Computers and Technology
1 answer:
Mila [183]2 years ago
3 0

Answer:

In  Java:

import java.util.*;

public class Main{

public static void main(String[] args) {

 Scanner input = new Scanner(System.in);

 String longstring, substring;

 System.out.print("Enter a long string: ");

 longstring = input.nextLine();

 System.out.print("Enter a substring: ");

 substring = input.nextLine();

 

 System.out.println("Length of your string: "+longstring.length());

 System.out.println("Length of your substring: "+substring.length());

 System.out.println("Starting position of your substring: "+longstring.indexOf(substring));

 

 String before = longstring.substring(0, longstring.indexOf(substring));

 System.out.println("String before your substring: "+before);

 

 String after = longstring.substring(longstring.indexOf(substring) + substring.length());

 System.out.println("String after your substring: "+after);

 

 System.out.print("Enter a position between 0 and "+(longstring.length()-1)+": ");

 int pos;

 pos = input.nextInt();

 System.out.println("The character at position "+pos+" is: "+longstring.charAt(pos));

 

 System.out.print("Enter a replacement string: ");

 String repl;

 repl = input.nextLine();

 

 System.out.println("Your new string is: "+longstring.replace(substring, repl));

 System.out.println("Goodbye!");

}

}

Explanation:

<em>Because of the length of the explanation; I've added the explanation as an attachment where I used comments to explain the lines</em>

<em></em>

Download txt
You might be interested in
What is technology in computer​
qaws [65]

Answer:

she is right or he :)

Explanation:

8 0
3 years ago
Write a function called first_last that takes a single parameter, seq, a sequence. first_last should return a tuple of length 2,wh
motikmotik

Answer:

The Python code with the function is given below. Testing and output gives the results of certain chosen parameters for the program

Explanation:

def first_last(seq):

   if(len(seq) == 0):

       return ()

   elif(len(seq) == 1):

       return (seq[0],)

   else:

       return (seq[0], seq[len(seq)-1])

#Testing

print(first_last([]))

print(first_last([1]))

print(first_last([1,2,3,4,5]))

# Output

( )

( 1 , )

( 1 , 5 )

5 0
3 years ago
The _____ element, a hypertext markup language (html) metadata element, contains a collection of metadata elements that describe
Butoxors [25]
The "head" element, a hypertext markup....
Missing word is head
5 0
3 years ago
Read 2 more answers
Identify the careers that require a college degree
Vikentia [17]
Doctor or teacher or an engineer

8 0
2 years ago
What method can be used to determine if an email link is authentic?
Sloan [31]
A password and pin hope this helps :D
3 0
3 years ago
Other questions:
  • )in the link based implementation of the ADT sorted list what is the worst case time efficiency of the remove method?
    7·1 answer
  • Define and test a function myRange. This function should behave like Python’s standard range function, with the required and opt
    11·2 answers
  • what type of clause must you always use with DEKETE or UPDATE to avoid inadvertently changing data elsewhere in the database​
    12·1 answer
  • Select the statement that accurately describes why the Italics function is being used in the sentences below.
    8·1 answer
  • T F A stub is a dummy function that is called instead of the actual function it<br><br> represents.
    7·1 answer
  • Write a program that first gets a list of integers from input. The input begins with an integer indicating the number of integer
    7·1 answer
  • Write a brief, two-page paper describing how your lifestyle and values impact your use of the Web for e-commerce. How is your on
    15·1 answer
  • Besides earning money why do people work​
    6·2 answers
  • Examples of application software​
    7·2 answers
  • Your friends are having difficulties with their computer setups. Can you suggest a way to help each friend?
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!