Levels Tought:
Elementary,Middle School,High School,College,University,PHD
Teaching Since: | Jul 2017 |
Last Sign in: | 211 Weeks Ago, 3 Days Ago |
Questions Answered: | 15833 |
Tutorials Posted: | 15827 |
MBA,PHD, Juris Doctor
Strayer,Devery,Harvard University
Mar-1995 - Mar-2002
Manager Planning
WalMart
Mar-2001 - Feb-2009
I need the prgram to change the word cartons to tcaronst plz dont only give the code I also need an explanation on how to do it and how i would change other letters aroudn if i needed to thanks! this is what i have so far
Â
import java.util.Scanner;
/**
 * CS 170 Proficiency Quiz 4.
 * InsideOut2 program.
 *
 * @author Summer 17
 */
public class InsideOut2
{
  /**
   * Write the insideOut2() function.
   *
   * @param str an even-length String of at least 2 characters.
   * @return a String as described below.
   *
   * The function has one parameter: a String strÂ
   * that is at least 2 characters long and of evenÂ
   * length. The function returns a new String whereÂ
   * the middle two characters have been removedÂ
   * and placed at the end.Â
   *Â
   * Here some sample input and output:
   *  insideOut2 ("Carton") returns "Caonrt" // rt moved to end
   *  insideOut2 ("Hi") returns "Hi" // Hi removed and then moved to end, so no change.Â
   *  insideOut2 ("Barbara Anne") returns "Barba Annera" //ra moves end.
   */
  // TODO WRITE THE FUNCTION insideOut2 HERE
  public static void main(String[] args)Â
  {
    Scanner in = new Scanner(System.in);
    System.out.print("Type the String to be converted: ");
    String str = in.nextLine();
    System.out.println(insideOut2(str));
  }
  Â
  public static String insideOut2(String str)Â
  {
    int wordLen = str.length();
    int centerLen = wordLen / 2;
    Â
    //output
    String answer = (str.substring(0, centerLen - 1))
      + (str.substring(centerLen + 1, wordLen))
          + (str.substring(centerLen - 1, centerLen + 1));
       Â
        return answer;
        }
}
----------- Â ----------- H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly