package 002;
import java.util.Scanner; //用于从指定的字符串扫描数据
public class A{
public static void main(String[]args){
int[] arr1={-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};//我认为把数据复制来最直观
int sum=0;
for(int i=1;i<=100;i++)
{
sum+=Ai;
}
System.out.println("start");
int start=nextInt();
System.out.println("end");
int end=nextInt;
System.out.println(start=start+);
System.out.println(end=end+);
for(int i=start;i<=end;i++);/*这边用start/end做下标(start/end是自己定义的,可以根据start/end来任取数组的范围,像是startA20,endA66,即可实现A20到A66的求和运算*/
sum+=Ai;
System.out.println(sum);
}
package 002;
public class B {
public static void main(String[]args){
int[][]a={{-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}};;//定义的一个二维数组是参考javaEE基础教程这本书上的一个二维数组的例子
a=new int[100][];//初始化a是一个长度为100的数组,a数组的数组元素又是引用类
int sum=0;
for(int i=0;i<a.length;i++)
for(int j=0;j<a.length;j++)
sum+=a[i][j]
{
System.out.println(a[i][j]);
}
a[0]=new int[2];//初始化a数组的第一个元素
a[0][1]=6;//访问a数组的第一个元素所指数组的第二个数组
for(int i=0;i<a[0].length;i++)//a数组的第一个元素是一个一维数组,遍历这个一维数组
{
System.out.println(sum);
}
package 002;
public static void main(String[]args)
{
int sum=0;
int[][][] a =
{
{{-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}},
{{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}}
};//三维数组的定义是同二维数组
int a=new int[100][][];//初始化a是一个长度为100的数组,a数组的元素还是引用类
int sum=0;
for(int i=0;i<a.length;i++)
for(int j=o;j<a.length;j++)
for(int q=o;q<a.length;q++)
sum+=a[i][j][q];
a[0]=new int[2];//初始化a数组的第一个元素
a[0][1]=6;//访问a数组的第一个元素所指数组的第二个数组
for(int i=0;i<a[0].length;i++)
{
System.out.println(sum);
System.out.println(sum);
}
心得体会和小结:
一看到题目的时候觉得很简单,不就是分别实现一百个数,两百个数,三百个数相加嘛,后来问了几个同学,他们是实现几百个数相加,但是也没简单。老师给的Excle表中有几千个数,我们要实现任意范围内的几百个数相加。于是我就犯愁了,顿时没了头绪。对于在任意范围内的几百个数相加,那在编写代码的时候就该给数加上标签,但是有那么多的数,总不能每个加上标签吧,几十个几百个数也许还是依次加上标签,但是像这样几千几万那么多的数怎么加啊,而且相加的数还不是只有一维的,有二维和三维的。不知道怎么去实现,于是我问了林杰同学,他说我可以在for循环里做文章,可以任意将i的初始值和最终的值替换,然后试着用start和end替换掉for循环里的1和100.我把第一个一维数组做完之后,发现这个方法还是挺好用的,但是在后面的二维和三维的数组上我不想我把这样用,于是我吧上学期的javaEE的书翻出来把数组的那张看了一遍发现在处理二维数组的时候,可以将二维数组当成一维数组来遍历二位数组里的每个元素。所以我在处理二维数组上的任意两百个数相加的时候,参考了书上的一个例题,但是我有修改了一下,很不巧的是我的Tomcat和my eclipse坏掉了,测试不了,卸了重装好几次也不行。但是我知道我的代码应该是有些问题的,基础不是很好,编的不完美。但是我在完成一维数组任意范围求和之后再继续二维和三维数组,发现通过一位数组的代码类比出来的二维和三维数组的代码还是相对简单的。
还有就是每次的软件工程的工程,都会迫使我去看之前没学好的内容,温故而知新,收获颇多!