package com.randy.test;
public class Demo2 {
/**
* 0,1,2,3,4,6,7,8,9,10,13,14
*
* 结果
* 1-4
* 6-10
* 13-16
* */
public static void main(String[] arg0){
int[] number=new int[]{0,1,2,3,4,6,7,8,9,10,13,14};
int count=0;
for(int i=0;i<number.length;i++){
if(i+1!=number.length){
if(number[i]!=number[i+1]-1){
System.out.println(number[i-count]+"______"+number[i]);
count-=count+1;
}
count+=1;
}else{
if(count!=0){
System.out.println(number[i-count]+"______"+number[i]);
}
}
}
}
}
java一种计算
最新推荐文章于 2022-04-22 12:05:00 发布