fork download
  1. import java.util.Scanner;
  2.  
  3. public class StringManips
  4. {
  5. public static void main (String[] args)
  6. {
  7. String phrase;
  8. int phraseLength; // number of characters in the phrase String
  9. int middleIndex; // index of the middle character in the String
  10. String firstHalf; // first half of the phrase String
  11. String secondHalf; // second half of the phrase String
  12. String switchedPhrase; // a new phrase with original halves switched
  13.  
  14. //read in a phrase
  15. Scanner scan = new Scanner(System.in);
  16. System.out.println("Please enter a phrase:");
  17. phrase = scan.nextLine();
  18.  
  19.  
  20. // compute the length and middle index of the phrase
  21. phraseLength = phrase.length();
  22. middleIndex = phraseLength / 2;
  23.  
  24. // get the substring for each half of the phrase
  25.  
  26. String phrasefirst = substring (firstHalf,middleIndex);
  27. String phrasesecond = substring (middleIndex,secondHalf);
  28.  
  29. // concatenate the firstHalf at the end of the secondHalf
  30.  
  31.  
  32.  
  33. // print information about the phrase
  34. System.out.println();
  35. System.out.println ("Original phrase: " + phrase);
  36. System.out.println ("Length of the phrase: " + phraseLength +
  37. " characters");
  38. System.out.println ("Index of the middle: " + middleIndex);
  39. System.out.println ("Character at the middle index: " +
  40. phrase.charAt(middleIndex));
  41.  
  42.  
  43. System.out.println();
  44. }
  45. }
  46.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:3: error: class StringManips is public, should be declared in a file named StringManips.java
public class StringManips
       ^
Main.java:26: error: cannot find symbol
	String phrasefirst = substring (firstHalf,middleIndex);
	                     ^
  symbol:   method substring(String,int)
  location: class StringManips
Main.java:27: error: cannot find symbol
	String phrasesecond = substring (middleIndex,secondHalf);
	                      ^
  symbol:   method substring(int,String)
  location: class StringManips
3 errors
stdout
Standard output is empty