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]
3 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]3 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
Run the browser checker to see that the computer you are using now is set up for WileyPLUS. Which of the following browser funct
True [87]

Answer:

Mobile View

Explanation:

WileyPLUS is a web-based application that assists instructors in preparing for classes and lectures and automates the process of assigning and grading homework. It allows students to access the WileyPLUS course material and complete their homework online and receive instant feedback on their work.

WileyPLUS system requirements:

System Hardware:

<em>PC: Pentium IV or better with 256MB of RAM (minimum 256MB of RAM) </em>

<em>Mac: G4 Processor 733MHz or better with 512MB of RAM (minimum 128MB of </em>

<em>RAM) </em>

Operating Systems:

<em>PC: Windows 98 / 2000 / ME / XP </em>

<em>Mac: OS X (minimum of 10.2.8; 10.3.1 or better is recommended) </em>

Browsers:

<em>PC: Internet Explorer v6.0 or better;</em>

<em>Mozilla FireFox 1.0 or better</em>

<em>Mac: Safari 1.3 or better </em>

4 0
3 years ago
A way to have cells in your spreadsheet change formats based on the value of the cells is called _____.
ki77a [65]
Should be conditional filtering 
8 0
3 years ago
#Draw patterns using fibonacci
agasfer [191]

Answer:

yidRYoYORoydzyrozoyrsoyraoyeahplhDogdaoyeayeoayorahdlHDLgksOyeayeazhldhdlHkdOyaoyaerhaahdLhKDoywaeya9yaeya9eeY9ey9

7 0
3 years ago
Which of the following is NOT an example of one of the six primary ways businesses use the Internet?
pishuonlain [190]
The answer is c to manufacture new products because it is not hardware the internet can not produce products
3 0
4 years ago
Read 2 more answers
A flashing symbol that allows you to input text.
zlopas [31]
The correct answer is A. Cursor
4 0
4 years ago
Read 2 more answers
Other questions:
  • Which element in Access is an ideal data source?
    12·2 answers
  • ________ network each device is connected directly to a central network switch.
    8·1 answer
  • What does microsoft recommend for large organizations requiring desktop virtualization for many clients? quizlewt?
    10·1 answer
  • In printing systems using ____, a disk accepts output from several users and acts as a temporary storage area for all output unt
    14·1 answer
  • True or false: It can take some time for the labs to load once you click “start lab.”
    7·1 answer
  • 8.Which of the following IC was used in third generation of computers?Immersive Reader
    13·1 answer
  • Hi wanna play fortnite tomorrow add me im batjoker09 no caps or spaces
    13·1 answer
  • The computer that can be used for performing the daily life tasks that might include emailing, browsing, media sharing, entertai
    11·1 answer
  • Hey does anyone know how to fix a computer that goes on and off. It is a Asus chromebook and putting it into recovery mode didn'
    5·2 answers
  • A _ is the acknowledgment of a potential noncomformity, or an opinion regarding an issue that is not covered by a standard
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!