import java.util.Scanner; /** * Program that removes the middle character of a string. * * @author Steven Karas */ public class MidBlaster { public static void main(String[] args) { Scanner scan = new Scanner(System.in); /* * It's important to make the distinction between a string and a word. A * string is a sequence of characters stored together. A word is a * couple of letters, seperated by spaces. * * You can read words using scan.next(), but strings are read with * scan.nextLine(). */ // Get the number from the user System.out.print("Enter a string: "); String word = scan.nextLine(); /* * There may be another way to do this. It's important to remember to * use helper variables with algorithms like this. Otherwise the code * can turn out really long and impossible to understand. */ // break up the word around the center character. String prefix = word.substring(0, word.length() / 2); String suffix = word.substring(word.length() / 2 + 1, word.length()); // output the new word System.out.println(prefix + suffix); } }