you will debug the code which has been provided in the starter file. The code is...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
you will debug the code which has been provided in the starter file. The code is intended to take two strings, s1 and s2 followed by a whole number, n, as inputs from the user, then print a string made up of the first n letters of s1 and the last n letters of s2. Your job is to fix the errors in the code so it performs as expected (see the sample run for an example). Sample run Enter first string. sausage Enter second string races Enter number of letters from each word 3 sauces Note: you are not expected to make your code work when n is bigger than the length of either string. 1- import java.util.Scanner; 2 3. public class U2_L4_Activity_one { public static void main(String[] args) { 4- Scanner scan Scanner(System.in); 8 //Get first string 9 System.out.println("Enter first string"); String s1= nextLine(); //Get second string System.out.println("Enter second string"); String s2 = Scanner.nextLine(); ANM&In 1000 OHN 6 7 10 11 12 13 14 15 16 17 18. 19 20 21 22 23 24 G } //Get number of letters to use from each string System.out.println("Enter number of letters from each word"); String n = scan.nextLine(); //Print start of first string and end of second string System.out.println(s1.substring(1,n-1) + s2.substring(s1.length()-n)); you will debug the code which has been provided in the starter file. The code is intended to take two strings, s1 and s2 followed by a whole number, n, as inputs from the user, then print a string made up of the first n letters of s1 and the last n letters of s2. Your job is to fix the errors in the code so it performs as expected (see the sample run for an example). Sample run Enter first string. sausage Enter second string races Enter number of letters from each word 3 sauces Note: you are not expected to make your code work when n is bigger than the length of either string. 1- import java.util.Scanner; 2 3. public class U2_L4_Activity_one { public static void main(String[] args) { 4- Scanner scan Scanner(System.in); 8 //Get first string 9 System.out.println("Enter first string"); String s1= nextLine(); //Get second string System.out.println("Enter second string"); String s2 = Scanner.nextLine(); ANM&In 1000 OHN 6 7 10 11 12 13 14 15 16 17 18. 19 20 21 22 23 24 G } //Get number of letters to use from each string System.out.println("Enter number of letters from each word"); String n = scan.nextLine(); //Print start of first string and end of second string System.out.println(s1.substring(1,n-1) + s2.substring(s1.length()-n));
Expert Answer:
Answer rating: 100% (QA)
I see several issues in your code that need to be fixed Heres the corrected code import javautilScan... View the full answer
Related Book For
Java An Introduction To Problem Solving And Programming
ISBN: 9780134462035
8th Edition
Authors: Walter Savitch
Posted Date:
Students also viewed these programming questions
-
If the 5- and 5.5-year par yields are both at 2%, compute the forward rate from 5 to 5.5 years.
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
Start of Payroll Project 7-3a October 9, 20-- No. 1 The first payroll in October covered the two workweeks that ended on September 26 and October 3. This payroll transaction has been entered for you...
-
A process is controlled with a fraction nonconforming control chart with three-sigma limits, n = 100, UCL = 0.161, center line = 0.080, and LCL = 0. (a) Find the equivalent control chart for the...
-
The resistance R of a blood vessel to the flow of blood is a function of the radius r of the blood vessel and is given by R = k / r4 where k is a constant. Find the percent rate of change of the...
-
Joe is the production scheduler in a brand- new custom refinishing auto service shop located near the border. This system is capable of handling 10 cars per day. The sequence is customizing first,...
-
We hope that you are part of a study group or, if that is not possible, that you have a telephone, e-mail, instant messaging, or webcam study buddy (or even more than one). And, of course, plenty of...
-
What are the objectives, inputs, and outputs of an MRP system?
-
How can organizations balance productivity demands with employee well-being, and what are the long-term consequences of neglecting work-life balance ?
-
If the coefficient of static friction between all the surfaces of contact is s, determine the force P that must be applied to the wedge in order to lift the brace that supports the load F. N' PNA B....
-
At the start of the current year, SBC Corp. purchased 25% of Sky Tech Inc. for $54 million. At the time of purchase, the carrying value of Sky Tech's net assets was $94 million. The fair value of Sky...
-
How much energy is required to heat \(100 \mathrm{~L}\) of water from \(20^{\circ} \mathrm{C}\) to \(55^{\circ} \mathrm{C}\) ?
-
You are given 13.0 m of thin wire. You form the wire into a circular coil with 50 turns. If this coil is placed with its axis parallel to a 0.12 T magnetic field, what is the flux through the coil?
-
An inventor designs a model plane that uses the emf that develops across its metal wings as it flies through the earths magnetic field to power the planes propeller. Will this plane be able to power...
-
Experimentally one obtains \(C_{P}=4.844 \times 10^{-23} \mathrm{~J} / \mathrm{K}\) for nitrogen gas at room temperature. (a) Calculate the heat capacity ratio \(\gamma\) for a gas of nitrogen...
-
Residents of Lake Caliopa, Minnesota, began noticing an unusually high number of lung ailments among the local population. Several concerned citizens pooled their resources and commissioned a study...
-
What are different types of exceptions in java? . Explain in detail with code.
-
If |62x|>9, which of the following is a possible value of x? A. 2 B. 1 C. 0 D. 4 E. 7
-
Repeat the previous exercise, but write the new lines to a new binary file instead of a text file. Previous exercise Write a program that reads every line in a text file, removes the first word from...
-
The following code fragment will not compile. Why? if !x > x + y x = 2 * x; else x = x + 3;
-
Suppose that we want to compute the geometric mean of a list of positive values. To compute the geometric mean of k values, multiply them all together and then compute the kth root of the value. For...
-
A healthy diet is becoming increasingly important for consumers, especially women aged 2535. As a result, they are taking active steps to ensure they are eating healthy but are also looking for other...
-
Lael was just hired by Best East Motels into their manager training program and was excited about the potential benefits after her graduation from Florida State University. Working part-time and...
-
Sophie just completed a sales training course with one of the firms most productive sales representatives, Emma. At the end of the first week, Sophie and Emma sat in a motel room filling out their...
Study smarter with the SolutionInn App