哪位大神能帮忙把一串数例如1,2,3,4,2,3,4,5,6,1,2,3,4,5,6,3,4,5,6,7.按拐点输出
第一行输出1,2,3,4。第二行2,3,4,5,6。第三行1,2,3,4,5,6。第四行4,5,6,7
谢谢大神的帮助啊!!!

解决方案 »

  1.   

    int[20] a = {1,2,3,4,2,3,4,5,6,1,2,3,4,5,6,3,4,5,6,7};
    String str = a[0] + ",";
    for(int i = 0; i < 19 ; i++){
    if( a[i] < a[i+1] ) {
    str += a[i+1] + ",";
    if( i == 18 )
    System.out.println(str.length - 1);
    } else {
    System.out.println(str.length - 1);
    str = a[i+1];
    }

    }这样写虽然笨一点,不过应该可以实现。你试试
      

  2.   

    应该可以实现
    int[20] a = {1,2,3,4,2,3,4,5,6,1,2,3,4,5,6,3,4,5,6,7};
    boolean flag = true;
    for(int i=0;i<a.length;i++)
    {
    System.out.print(a[i]+" ");
    if(a[i]<a[i+1]
    flag=false;
    if(flag==flase)
    {
    System.out.println("");
    flag = true;
    }
    }
      

  3.   

    反了
    int[20] a = {1,2,3,4,2,3,4,5,6,1,2,3,4,5,6,3,4,5,6,7};
    boolean flag = true;
    for(int i=0;i<a.length;i++)
    {
    System.out.print(a[i]+" ");
    if(a[i]>a[i+1]
    flag=false;
    if(flag==flase)
    {
    System.out.println("");
    flag = true;
    }
    }
      

  4.   

    运行结果:
    1 2 3 4 
    2 3 4 5 6 
    1 2 3 4 5 6 
    3 4 5 6 代码:
    package www.ygpt.org;/** 阳光平台 www.ygpt.org */
    public class Ygpt {
    public static void main(String[] args) {
    int[] a = { 1, 2, 3, 4, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 3, 4, 5, 6, 7 };
    boolean flag = false;
    for (int i = 0; i < a.length - 1; i++) {
    System.out.print(a[i] + " ");
    if (a[i] > a[i + 1])
    flag = true;
    if (flag) {
    System.out.println("");
    flag = false;
    }
    }
    }
    }以上代码,已上机调试运行通过。
      

  5.   

    int[] s={那串数字};
    for(int i=1:i<s.length;i++){
    if(s[i]>=s[i-1]){
    System.out.print(s[i]);
    }else{
    System.out.println(s[i]);
    }
    }
      

  6.   

    8楼标记,呵呵
     int[] a = {1, 2, 3, 4, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 3, 4, 5, 6, 7};
            for (int i = 0; i < a.length - 1; i++)
            {
                System.out.print(a[i]);
                if (a[i] + 1 != a[i + 1])
                {
                   System.out.println();
                }
            }
      

  7.   

    楼上都说过了..我就不贴代码了..基本就是for if
      

  8.   


    int[] a = new int[]{1, 2, 3, 4, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 3, 4, 5, 6, 7};
            for (int i = 1; i < a.length; i++) {
                System.out.print(a[i - 1] + ((a[i - 1] > a[i]) ? ",\r\n" : ", "));
            }
            System.out.print(a[a.length - 1]);
      

  9.   

    public class GuanDian { /**
     * @param args
     */
    public static void main(String[] args) {
    // TODO Auto-generated method stub int []arr={1,2,3,4,2,3,4,5,6,1,2,3,4,5,6,3,4,5,6};
    boolean result=true;
    for (int i = 0; i < arr.length-1; i++) {
    System.out.print(arr[i]+",");
    if(arr[i]>arr[i+1])
       result=true;
    else
       result=false;
    }
    }
    }
    在控制台输出的是:1,2,3,4,2,3,4,5,6,1,2,3,4,5,6,3,4,5,怎么少一个6???
      

  10.   

    int[] s = { 1, 2, 3, 4, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 3, 4, 5, 6, 7 };
    for (int i = 1; i < s.length; i++) {
    if (s[i] >= s[i - 1]) {
    System.out.print(s[i - 1]);
    } else {
    System.out.println(s[i - 1]);
    }
    }