Question: you will debug the code which has been provided in the starter file. The code is intended to take two strings, s1 and s2
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));
Step by Step Solution
3.33 Rating (150 Votes )
There are 3 Steps involved in it
I see several issues in your code that need to be fixed Heres the corrected code import javautilScan... View full answer
Get step-by-step solutions from verified subject matter experts
