fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main(String[] args) {
  11.  
  12. //Ask user what word they would like to "pyramid"
  13. String input = "pyramid";//
  14. wordPyramid(input);
  15.  
  16. }
  17.  
  18. //Create word pyramid method
  19. public static String wordPyramid(String word) {
  20. int length = word.length();
  21. System.out.println(word);
  22. if (word.length() == 1) {
  23. return word;
  24. }
  25. else {
  26.  
  27. return word = wordPyramid(word.substring(1, length-1));
  28. }
  29.  
  30. }
  31.  
  32. }
Success #stdin #stdout 0.11s 320256KB
stdin
Standard input is empty
stdout
pyramid
yrami
ram
a