This document discusses repositioning a hyphen in a string to the beginning. It provides an example of taking the string "face-prep" and transforming it to "-faceprep" by using a method that finds the index of the hyphen, takes the substring before it, adds a hyphen to the beginning, and appends the remaining substring. The method is demonstrated in a simple Java program to print the transformed string.
This document discusses repositioning a hyphen in a string to the beginning. It provides an example of taking the string "face-prep" and transforming it to "-faceprep" by using a method that finds the index of the hyphen, takes the substring before it, adds a hyphen to the beginning, and appends the remaining substring. The method is demonstrated in a simple Java program to print the transformed string.
This document discusses repositioning a hyphen in a string to the beginning. It provides an example of taking the string "face-prep" and transforming it to "-faceprep" by using a method that finds the index of the hyphen, takes the substring before it, adds a hyphen to the beginning, and appends the remaining substring. The method is demonstrated in a simple Java program to print the transformed string.
This document discusses repositioning a hyphen in a string to the beginning. It provides an example of taking the string "face-prep" and transforming it to "-faceprep" by using a method that finds the index of the hyphen, takes the substring before it, adds a hyphen to the beginning, and appends the remaining substring. The method is demonstrated in a simple Java program to print the transformed string.
Move Hyphen to Beginning: Moving the hyphen to the beginning
refers to the task of repositioning a hyphen in a given string so thaat it appears at the beginning. For example, transforming “face-prep" into "-faceprep". public class MoveHyphenToBeginning { public static void main(String[] args) { String originalString = "face-prep"; String transformedString = moveHyphenToBeginning(originalString); System.out.println(transformedString); }
public static String moveHyphenToBeginning(String string) {
if (string.contains("-")) { int hyphenIndex = string.indexOf("-"); return "-" + string.substring(0, hyphenIndex) + string.substring(hyphenIndex + 1); } else { return string; } } } THANK YOU