Question: Java can you explain what each line of code does? Also this one specially which is higlighted import java.util.Scanner; public class StringManips { public static
import java.util.Scanner; public class StringManips { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String phrase = new String("This is a string test."); int phraseLength; int middleIndex; String firstHalf; String secondHalf; String switchedPhrase; String middle3; String city, state, hometown; phraseLength = phrase. length(); middleIndex = phraseLength / 2; firstHalf phrase.substring(0, middleIndex); secondHalf = phrase. substring(middleIndex, phraseLength); middle3 = phrase. substring(middleIndex - 1, middleIndex + 2); 12 switchedPhrase = secondHalf.concat(firstHalf); switchedPhrase = switched Phrase Lace System.out.print("Enter your city = sc.nextLine().trim(); System.out.print("Enter your state = sc.nextLine().trim() hometown = state.toUpperCase state.toUpperCase(); NO System.out.println(); System.out.println("original phrase: " + phrase); System.out.println("Length of the phrase: " + phraseLength + characters"); m.out.println("Index of the middle: " + middleIndex); System.out.println("Character at the middle index: " + phrase.charAt(middleIndex)); ystem.out.println("Switched phrase: " + switchedPhrase): System.out.println("The middle 3 characters: + middle3); System.out.println("Your modified hometown is: " + hometown); System.out.println()
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
