【问题标题】:While-loop with two values有两个值的 while 循环
【发布时间】:2022-11-28 02:58:02
【问题描述】:

我是一个初学者,试图了解如何编写一个 while 循环代码,按顺序写出数字,多少取决于循环。例如 loop(3,6) 结果为 3456。这是我到目前为止的尝试

public static void loop(int start, int end){

int loop = 1;
while( loop <= start && end < runLoop ){
     System.out.print( start + end ) ;
loop = loop+1;
    
   }
}

【问题讨论】:

    标签: java while-loop


    【解决方案1】:

    直接使用start,直到达到end

    public static void loop(int start, int end){
       while(start <= end){
          System.out.print(start);
          start++;    
       }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-03-08
      • 2021-11-29
      • 2011-08-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-23
      • 1970-01-01
      相关资源
      最近更新 更多