第二次作业(个人项目实践)
一
package A; import java.util.Scanner;//用于java输入语句的包。 public class a { public static void main(String[]args) { int[] arr={-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; Scanner sc = new Scanner(System.in) ;//定义Scanner类的对象sc,接收来自键盘的数据 System.out.println("开始x:"); int start=sc.nextInt(); System.out.println("结束y:"); int end=sc.nextInt(); System.out.println("str为:" +start); System.out.println("end为:" +end); System.out.println("第"+start+"个元素到第"+end+"个元素相加和为"); for(int i=start;i<=end;i++) sum+=arr[i]; System.out.println(arr[start - 1] + "+...+" + arr[end - 1] + "=" + sum); } }
实验结果 :
二
package aa; import java.util.Scanner; public class b { public static void main(String[]args){ int[][] arr={{-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}}; int sum=0; Scanner bb = new Scanner(System.in); System.out.println("开始x:"); int startI = bb.nextInt(); System.out.println("结束y:"); int endI = bb.nextInt(); System.out.println("开始x:"); int startJ = bb.nextInt(); System.out.println("结束y:"); int endJ = bb.nextInt(); System.out.println("第" + startI + "列第" + startJ + "行到第" + endI + "列第" + endJ + "行的和为:"); for (int i = startI - 1; i < endI; i++) { for (int j = startJ - 1; j < endJ ; j++) { sum += arr[i][j]; } } System.out.println(arr[startI - 1][startJ - 1] + "+...+" + arr[endI - 1][endJ - 1] + "=" + sum); } }
实验结果:
总结:
这次作业对我来说是一次大的进步,以前要写代码一看就很晕,总有自己写不了的心理。这次,通过舍友的帮助下,完成了作业,
第三次作业有点难,我还不会写,希望老师见谅。我觉得老师布置这些作业对我们帮助很大,能很好的锻炼我们的能力,通过这次
作业,了解了自己的能力。找到了很多不足,但在同学和老师的帮助下,自己学到了很多。再写三维的那道题时,觉得自己需要学
的还有很多(因为三维的做不出来)。这次作业让我感受到了编程的美,所以在将来的作业中,希望我们都会不断进步,希望在将来
的作业上我会做的更好。