如何在单词中的每个字符上返回一个字符?

时间:2014-10-02 01:18:42

标签: java for-loop char word

如果您输入happy,它将显示

ħ

P

P

ý

现在我有这个:

    public static void three(){

    String x = keyb.next();

         int  y= x.length();

    char []  word = new char [y];

        System.out.println("It has " + y);
    for (int i = 0; i < x.length(); i++) {
        System.out.println(x);
    }

}

只是让单词出现了多少个字符。但我只是想让每个角色都缩进。拜托,谢谢!

1 个答案:

答案 0 :(得分:2)

这很简单:

String str = "happy";
for (int i = 0 ; i < str.length() ; i++){
    System.out.println(str.charAt(i));
}