Software Engineering Operations 06

Source: Internet
Author: User

Experiment 6: Ring Array summation

Programmer: Lu Zequn

Date: 17:31:35

A

Design ideas:

1 Input Array length

2 input Array

2.2 The array becomes an array of loops,

            for (i= Length;i<2*length;i++)
              {
              arry[i]=arry[i-length];
             }
3   for maximum value solving

3.2 First determine number of cycles length

3.2.2 arry2[j]=arry[j]; table is the first integer

           3.2.3 The number of loops (length) of a subarray

& nbsp;                    // The sum of the current I elements is greater than 0, then add  arry2[i]=arry[i]+ Arry2[i-1];
                    ) // The sum of the current elements of I is less than 0, just take down the value of the next element directly
                     Arry2[i]=arry[i];   
             3.2.4 for max comparison ok

 4 output max                         

Two

Experiment Code:

1  Packageshuzu01;2 3 ImportJava.util.Scanner;4 Importjava.lang.*;5  Public classTest {6     7     Private Static Booleanflase;8     Private StaticScanner in;9@SuppressWarnings ("Unused")Ten      Public  Static voidMain (String arg[]) One     { A         intI,j=0; -Scanner input =NewScanner (system.in); -System.out.println ("Please enter the length of an array"); the         intLength=input.nextint (); -           -         int[]arry=New int[length]; -         int[]arry2=New int[length]; +          -System.out.println ("Please enter an array"); +          for(i=0;i<length;i++ ) A         { at              -             intA=input.nextint (); - IsNumeric (a); -             if(false) -                 { -System.out.println ("Please enter an integer"); in                   ints=input.nextint (); -                     toarry[i]=s; +                 } -arry[i]=A; theJ + +;  *         } $         //forming a ring arrayPanax Notoginseng          for(i=length;i<2*length;i++) -         { thearry[i]=arry[i-length]; +         } A         //Summation Maximum value the         intMax=arry[0]; +          for(j=0;j<length;j++) -         { $arry2[j]=Arry[j]; $max=Math.max (Max,arry[j]); -              for(i=j+1;i<length+j;i++) -             { the                 if(arry2[i-1]>=0)//the sum of the current elements of I is greater than 0 and then added . -Arry2[i]=arry[i]+arry2[i-1];Wuyi                 if(arry2[i-1]<0)//The sum of the current elements of I is less than 0, and the value of the next element is directly taken down. thearry2[i]=Arry[i];  -                  Wu                 //Maximum value found -max=Math.max (Max,arry2[i]); About             } $         } -System.out.print ("Maximum value" +max);//Print Maximum value -          -      A          +      the                  -          $          the          the          the         /*For (i=0;i<length;i++) the         { - System.out.println (Arry[i]); in         }*/ the      the     } About  the  the  the  +  -      Public Static BooleanIsNumeric (inta) the     {Bayi              if(!Character.isdigit (a)) the               {        the                  return false; -               } -            the            the            return true; the          } the  -}

(iv) Summary

The first thing to do is loop the array of days plus, followed by the array summation is the array overflow, over the range.

Software Engineering Operations 06

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.