0% found this document useful (0 votes)
7 views

TriangleWord Java

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

TriangleWord Java

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

//(c) A+ Computer Science

//www.apluscompsci.com
//Name -

public class TriangleWord


{
private String word;

public TriangleWord(String w)
{
word=w;
}
public String toString()
{
String output = generateTriangle();
return output+"\n";
}
public String generateTriangle() {
StringBuilder output = new StringBuilder("");
String suffixString = word.substring(1);
StringBuilder builderString = new StringBuilder(suffixString);
builderString = builderString.reverse().append(word);
String line = builderString.toString();
for (int i = 0; i < word.length(); i++) {
for (int j = 0; j < line.length(); j++) {
if (i + 1 == word.length() || Math.abs(j - line.length() /
2) == i) {
output.append(line.charAt(j));
} else {
output.append(" ");
}
}
output.append("\n");
}
return output.toString();
}
}

This study source was downloaded by 100000870539223 from CourseHero.com on 09-24-2024 18:38:16 GMT -05:00

https://www.coursehero.com/file/141976448/TriangleWordjava/
Powered by TCPDF (www.tcpdf.org)

You might also like