如何制作文本三角形文本框

时间:2013-01-23 09:34:57

标签: java palindrome

// The "PalinDrome" class.
import java.awt.*;
import hsa.Console;

public class PalinDrome
{
    static Console c;           // The output console

    public static void main (String[] args)
    {
        c = new Console ();

        c.println("Please enter a word");
           String word = c.readLine ();
        int i;
        int num = word.length ();
        String str = "";
        for (i = num - 1 ; i >= 0 ; i--)
            str = str + word.charAt (i);
        if (str.equals (word))
            c.println (word + " is a palindrome");
        else
            c.println (word + " is not a palindrome");

        str.equalsIgnoreCase(word);




        // Place your program here.  'c' is the output console
    } // main method
} // PalinDrome class

我在我的考试项目中创建了一个回文程序。我希望这些字母以三角形的形状出现。您对我如何做到这一点有什么建议吗?

1 个答案:

答案 0 :(得分:0)

用户string.format使用  \t\n构建三角形表单,具体取决于字符串的长度。使用另一个for循环来遍历字符串并在每组字符之前/之后追加适当的间距