【问题标题】:Continue to the next iteration继续下一次迭代
【发布时间】:2014-11-25 22:54:37
【问题描述】:

我只想知道是什么问题不让我的程序继续下一次迭代.. 这是我的代码:

  public static void main(String []args){
    int height = 5;
    int width = 10;


    for(int i =0; i<height; i++){
        char[] ligne ;
        do{
        System.out.println("tapez la ligne " + i + ":");
        Scanner sc = new Scanner(System.in);

        ligne = sc.next().toCharArray(); //



        } while(ligne.length != width);
    }
 }

结果总是:Tapez la ligne 0:

谢谢

【问题讨论】:

  • 你输入了什么? (我的意思是sc.next()
  • 你试过输入长度为10的字符串吗?或者您是否尝试过调试以更好地了解您的代码在做什么?
  • @LaroussiNader... 如果您输入一个字符,您的代码将永远不会超出 do {} while()... 您必须按照编写代码的方式输入长度为 10 的字符串。
  • 正如你在这里看到的while(ligne.length != width)a character 是不够的。输入类似0123456789

标签: java loops do-while


【解决方案1】:

如果您输入一个包含 10 个字符的字符串,您的内部循环 do{}while(cond) 将退出。 do{}while(cond) 仅在找到 cond 的倒数时才会退出。

【讨论】:

    猜你喜欢
    • 2011-04-26
    • 2020-04-08
    • 2010-12-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多