分离字符java

时间:2016-01-08 03:41:53

标签: java

无法打印出来。谁知道这笔交易是什么?

import java.util.Scanner;

public class SeparatingCharacters {

    public static void main(String[] args) {
        Scanner reader = new Scanner(System.in);
        System.out.println(" Please enter name");
        String text = reader.nextLine();
        int length = text.length(); 
        for (int i = 0; length == i; i++) {
        System.out.println(i + ". character: " + text.charAt(i));

        }
    }
}

2 个答案:

答案 0 :(得分:2)

检查你的for循环。 i=0length == i

编辑:应该是

for(int i=0; i < length; i++)

答案 1 :(得分:0)

你应该再次检查你的循环,你的条件错了。将$(document).ready(function() { $('.secondNav-widgets').hover(function() { if ($(this).hasClass('col-md-6')) { }else { $(this).find(".noShow").switchClass( "noShow", "show", 500, "easeInSine" ).fadeTo( "slow", 1 ); $('.secondNav-widgets').find(".show").fadeOut("slow", function () { $(this).removeClass("show", 0).addClass("noShow", 0).css({display:"none"}); }); $('.secondNav-widgets').switchClass( "col-md-6", "col-md-3", 1000 ); $(this).switchClass( "col-md-3", "col-md-6", 1000 ); } }); }); 修复为length == i然后应该没问题。

i < length

测试输出:

public static void main(String[] args) {
    Scanner reader = new Scanner(System.in);
    System.out.println(" Please enter name");
    String text = reader.nextLine();
    int length = text.length(); 
    for (int i = 0; i <  length; i++) {
    System.out.println(i + ". character: " + text.charAt(i));

    /* ---edit---
    make the print number start from 1
    System.out.println((i + 1) + ". character: " + text.charAt(i));
    */

    }
}