/*********************** * * Diamond - prints a String input by the user, as a triangle. * * Author: Shawn Brenneman * Date: 2015-Sep-23 * ***********************/ import java.util.Scanner; public class Diamond { public static void main(String[] args) { Scanner scan = new Scanner(System.in); System.out.print("Enter a sentence: "); String input = scan.nextLine(); int pos = 0; String accum = ""; while (pos < input.length()){ accum += input.charAt(pos); System.out.println(accum); pos++; } pos--; pos--; int ii = 0; while (pos >= 0) { ii = 0; while (ii < pos) { System.out.print(' '); ii++; } System.out.println(input.charAt(pos)); pos--; } } //main }