1. Design a class (called a) that implements the addition of elements within a specified range of one-dimensional arrays (a[100]). Array Length: 100, Range: Experimental data a column: 1~100,csv format fills the first 100 data
1 ImportJava.util.Scanner;2 3 Public classA {4 Public Static voidMain (string[] args) {5 int[] AA = {-2574,-4010, 8243, 771, 2447,-5197, 2556, 8044, 3314,63617, 6065,-2817, 3131, 6318, 2186,-113, 629,-2582, 37,7-1520, 164, 2055,-5936, 5912, 1717, 5988, 4781, 5757, 892,8-4394, 8034, 2213,-1080,-2080, 5364, 106, 2657, 566, 3940,9-5116, 4583, 1806, 6555, 2621,-7197, 528, 1626, 18, 1049,Ten6243, 3198, 4397,-1325, 9087, 936,-6291, 662,-178, 135, One-3473,-2385,-165, 1713,-7949,-4234, 1138, 2212, 104, 6968, A-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, the-4354,-1213, 767};//do not use CSV format, only use this method - intsum = 0; -Scanner A =NewScanner (system.in); -System.out.println ("Starting from the first (<=100):"); + intStart =a.nextint (); -System.out.println ("To the end of the first few (<=100):"); + intEnd =a.nextint (); ASystem.out.println ("First" + start + "elements to" + END + "Elements of" and "for:"); at - for(inti = start-1; I < end; i++) - //The first one is aa[0] -Sum + =Aa[i]; -System.out.println (Aa[start-1] + "+...+" + aa[end-1] + "=" +sum); - in } -}
Output result: (correct case)
(out of case)2. Design a class (which may be called B) to implement the addition of elements within a specified range of a two-dimensional array (a[n][m]). Array Length: (N*m approximately equal to A) column A, B: 1~100;
1 ImportJava.util.Scanner;2 3 Public classB {4 Public Static voidMain (string[] args) {5 int[] B = {6{-2574,-4010, 8243, 771, 2447,-5197, 2556, 8044, 3314, 3617,76065,-2817, 3131, 6318, 2186,-113, 629,-2582, 37,8-1520, 164, 2055,-5936, 5912, 1717, 5988, 4781, 5757,9892,-4394, 8034, 2213,-1080,-2080, 5364, 106, 2657,Ten566, 3940,-5116, 4583, 1806, 6555, 2621,-7197, 528, One1626, 18, 1049, 6243, 3198, 4397,-1325, 9087, 936, A-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, the1356, 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, A-5518, 5872, 870,-5175,-3961,-427,-6284, 2850, 481, at6175, 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, in-1680, 2321,-4617,-1961, 2076, 7309 } }; - intSum=0; toScanner BB =NewScanner (system.in); +System.out.println ("Starting from the first few columns:"); - intStarti =bb.nextint (); theSystem.out.println ("To the end of the first few columns:"); * intEndi =bb.nextint (); $System.out.println ("Starting from the first few lines:");Panax Notoginseng intSTARTJ =bb.nextint (); -System.out.println ("To the end of the first few lines:"); the intENDJ =bb.nextint (); +System.out.println ("First" + Starti + "column" + STARTJ + "line to" + Endi + "column" A+ Endj + "line and for:"); the + for(inti = startI-1; i < Endi; i++) - { $ for(intj = startJ-1; J < Endj; J + +) $ { -Sum + =B[i][j]; - } the } -System.out.println (B[starti-1][startj-1] + "+...+"Wuyi+ b[endi-1][endj-1] + "=" +sum); the } -}
Output Result:
(out of the picture is not attached)
Summarize:
do one and two-dimensional array of operations took a lot of time, three-dimensional array to establish space structure, really do not understand, asked Zhang Zhenji classmate, but still smattering, gave up three-dimensional array of work.
For the import of Excel data in CSV format, not at all, see the teacher to the method, completely do not understand, Baidu is still confused, preferring to use a simple point of the way, so still use the method of losing numbers, fortunately is 100, not too laborious. Since it is a manual input of 100 numbers, it also stipulates that the range of J in the one-dimensional array I and two-dimensional arrays is <=100, so there is no definition of the scope of I and J in the system, it is obvious anyway.
However, we have to say that these two programs are too restrictive, not suitable for widespread use, the numbers are hard to enter, hope that after this semester of learning, can learn something to make a perfect, but practical procedures.
Second assignment: Personal project Practice