Second assignment (personal project Practice)

Source: Internet
Author: User

1. Design a Class A to implement the addition of elements within a specified range of one-dimensional arrays

Source:

1  Packages001;2 ImportJava.util.Scanner;3  Public classA {4 5     6      Public Static intCountint[]arr,intStartintEndintsum) {7         8         9          for(inti=start;i<=end;i++)Tensum+=Arr[i]; One         returnsum; A     } -      Public Static voidMain (string[] args) { -          the        intS=0;  -         -        int[]a=New int[]{-2574,-4010,8243,771,2447,-5197,2556,8044,3314,3617,6065,-2817,3131,6318,2186,-113,629,-2582,-37,- 1520,164,2055,-5936,5912,1717,5988,4781,5757,892,-4394,8034,2213,-1080,-2080,5364,106,2657,566,3940,- 5116,4583,1806,6555,2621,-7197,528,1626,18,1049,6243,3198,4397,-1325,9087,936,-6291,662,-178,135,-3473,-2385,- 165,1713,-7949,-4234,1138,2212,104,6968,-3632,3801,1137,-1296,-1215,4272,6223,-5922,-7723,7044,-2938,- 8180,1356,1159,-4022,-3713,1158,-8715,-4081,-2541,-2555,-2284,461,940,6604,-3631,3802,-2037,-4354,-1213,767};  -        +Scanner sc=NewScanner (system.in); -System.out.println ("Please enter M, N:"); +        intm=sc.nextint (); A        intn=sc.nextint (); atSystem.out.println ("M for:" +m); -System.out.println ("N is:" +n); -         - A.count (a,m,n,s); -        -System.out.println ("sum=" +A.count (A, M, N, s)); in     } -}

A test:

Verify:

2. Design a class B to achieve the addition of elements within a specified range in a two-dimensional array

1  Packages001;2 ImportJava.util.Scanner;3 4  Public classB {5     6    Public Static intCountint[][]arr,intStart1,intStart2,intEnd1,intEnd2,intsum) {7       8        for(inti=start1;i<=end1;i++)9          {Ten               for(intj=start2;j<=end2;j++) One              { Asum+=Arr[i][j]; -              } -          }     the        returnsum; -              -     } -      +      Public Static voidMain (string[] args) { -          +          intS=0; A          int[] b=New int[][]{{-2574,-4010,8243,771,2447,-5197,2556,8044,3314,3617,6065,-2817,3131,6318,2186,-113,629,-2582,-37,- 1520,164,2055,-5936,5912,1717,5988,4781,5757,892,-4394,8034,2213,-1080,-2080,5364,106,2657,566,3940,- 5116,4583,1806,6555,2621,-7197,528,1626,18,1049,6243,3198,4397,-1325,9087,936,-6291,662,-178,135,-3473,-2385,- 165,1713,-7949,-4234,1138,2212,104,6968,-3632,3801,1137,-1296,-1215,4272,6223,-5922,-7723,7044,-2938,- 8180,1356,1159,-4022,-3713,1158,-8715,-4081,-2541,-2555,-2284,461,940,6604,-3631,3802,-2037,-4354,-1213,767},{ 2740,-4182,-5632,-2966,-1953,567,-8570,1046,2211,1572,-2503,-1899,3183,-6187,3330,3492,-464,- 2104,316,8136,470,50,466,-1424,5809,2131,6418,-3018,6002,-8379,1433,1144,2124,1624,-602,-5518,5872,870,-5175,- 3961,-427,-6284,2850,481,6175,141,-766,-1897,-748,-4248,366,4823,3003,1778,3256,2182,2253,5076,5540,-2650,2451 , -1875,5482,-6881,-329,-969,-8032,-2093,612,1524,-5492,5758,-7401,-5039,3241,6338,3581,4321,- 1072,4942,2131,210,-7045,-7514,7450,-1142,-2666,-4485,-639,2121,-5298,-3805,-1686,-2520,-1680,2321,-4617,-1961,2076,7309 }};  at          -Scanner sc =NewScanner (system.in); -System.out.println ("Please enter M1,N1,M2,N2:"); -           -           intM1 =sc.nextint (); -           intN1 =sc.nextint (); in            -System.out.println ("m1=" +M1); toSystem.out.println ("n1=" +N1); +            -           intM2 =sc.nextint (); the           intN2=sc.nextint (); *            $System.out.println ("m2=" +m2);Panax NotoginsengSystem.out.println ("n2=" +n2); -            the B.count (b,m1,n1,m2,n2,s); +System.out.println ("sum=" +B.count (b,m1,n1,m2,n2,s)); A     }      the  +}

B Test:

Verify:

3. Design a class C to implement the addition of elements within a specified range of three-dimensional arrays

1  Packages001;2 ImportJava.util.Scanner;3 4  Public classC {5     6      Public Static intCountint[][][]arr,intStart1,intEnd1,intStart2,intEnd2,intStart3,intEnd3,intsum) {7         8          for(inti=start1;i<=end1;i++)9          {Ten               for(intj=start2;j<=end2;j++) One              { A                   for(intk=start3;k<=end3;k++) -                  { -sum+=Arr[i][j][k]; the                                    -                  } -                   -              } +          }     -           returnsum; +              A     } at      Public Static voidMain (string[] args) { -          -          intS=0; -          int[][][] C =New int[][][]{ -{{ -2574,-4010,8243,771,2447,-5197,2556,8044,3314,3617,6065,-2817,3131,6318,2186,-113,629,-2582,-37,- 1520,164,2055,-5936,5912,1717,5988,4781,5757,892,-4394,8034,2213,-1080,-2080,5364,106,2657,566,3940,- 5116,4583,1806,6555,2621,-7197,528,1626,18,1049,6243,3198,4397,-1325,9087,936,-6291,662,-178,135,-3473,-2385,- 165,1713,-7949,-4234,1138,2212,104,6968,-3632,3801,1137,-1296,-1215,4272,6223,-5922,-7723,7044,-2938,- 8180,1356,1159,-4022,-3713,1158,-8715,-4081,-2541,-2555,-2284,461,940,6604,-3631,3802,-2037,-4354,-1213,767}},  -{{2740,-4182,-5632,-2966,-1953,567,-8570,1046,2211,1572,-2503,-1899,3183,-6187,3330,3492,-464,- 2104,316,8136,470,50,466,-1424,5809,2131,6418,-3018,6002,-8379,1433,1144,2124,1624,-602,-5518,5872,870,-5175,- 3961,-427,-6284,2850,481,6175,141,-766,-1897,-748,-4248,366,4823,3003,1778,3256,2182,2253,5076,5540,-2650,2451 , -1875,5482,-6881,-329,-969,-8032,-2093,612,1524,-5492,5758,-7401,-5039,3241,6338,3581,4321,- 1072,4942,2131,210,-7045,-7514,7450,-1142,-2666,-4485,-639,2121,-5298,-3805,-1686,-2520,-1680,2321,-4617,- 1961,2076,7309}}, in{{302,-7944,-6551,6648,-884,-6332,1188,-248,3902,-2171,-3782,-3510,6203,-636,-4605,4497,3187,-6278,1198,- 7963,7647,-3022,-8267,7995,-1998,-4171,730,-8117,-1706,7601,-2454,-6161,-1810,243,-2841,- 5377,2985,2328,177,5622,3596,3057,2830,-1151,6566,2254,6972,-3060,4063,367,84,3156,3880,-1530,5272,1385,-565,- 1736,1267,-3863,-229,2072,2423,-7449,9555,2844,-1278,-3613,-919,4153,-4232,4032,-5732,199,4792,2498,-3344,- 4193,2650,-579,3416,-3575,1822,-6936,-2661,-1873,414,2314,6844,7613,-7844,6680,5974,2208,-3597,6302,4396,-141, -1864,1939}} -             to         }; +Scanner sc=NewScanner (system.in); -System.out.println ("Please enter M1,N1,M2,N2,M3,N3:"); the            intM1 =sc.nextint (); *            intN1 =sc.nextint (); $System.out.println ("m1=" +M1);Panax NotoginsengSystem.out.println ("n1=" +N1); -                the            intM2 =sc.nextint (); +            intN2=sc.nextint (); ASystem.out.println ("m2=" +m2); theSystem.out.println ("n2=" +n2); +                -            intM3 =sc.nextint (); $            intn3=sc.nextint (); $System.out.println ("m3=" +m3); -System.out.println ("n3=" +n3); -                the C.count (c,m1,n1,m2,n2,m3,n3,s); -System.out.println ("sum=" +C.count (c,m1,n1,m2,n2,m3,n3,s));Wuyi    } the    -      Wu}

C Test:

Verify:

Summary:

When I first started this topic, I did not understand the teacher's meaning, completely irrelevant. Later saw the class of students and teachers of the chat record, just know that they want to biased. But still do not know from where to start, later refer to Jerrick classmate do, have a little idea but still not clear. Later saw the Yu-yu teacher and the teacher said, with a little inspiration. Due to the deadline for homework, the first thing to do, and then slowly improve it, see so cumbersome code I was drunk. I hope the teacher can guide

Second assignment (personal project Practice)

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.