Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Java
can you explain what each line of code does?
Also this one specially which is higlighted image text in transcribed
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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2017 Skopje Macedonia September 18 22 2017 Proceedings Part 3 Lnai 10536

Authors: Yasemin Altun ,Kamalika Das ,Taneli Mielikainen ,Donato Malerba ,Jerzy Stefanowski ,Jesse Read ,Marinka Zitnik ,Michelangelo Ceci ,Saso Dzeroski

1st Edition

ISBN: 3319712721, 978-3319712727

Students also viewed these Databases questions