JAVA中数组总结(课堂总结)

时间:2022-09-03 12:07:00

数组的特点:

Arrays(数组)
一种简单的数据结构
元素具有相同的数据类型
一旦创建之后,尺寸保持不变
元素在内存中连续分布
例子一:按引用与按值传递的示例
源代码:

// PassArray.java
// Passing arrays and individual array elements to methods public class PassArray { public static void main(String[] args) {
int a[] = { 1, 2, 3, 4, 5 };
String output = "The values of the original array are:\n"; for (int i = 0; i < a.length; i++)
output += " " + a[i]; output += "\n\nEffects of passing array " + "element call-by-value:\n"
+ "a[3] before modifyElement: " + a[3]; modifyElement(a[3]); output += "\na[3] after modifyElement: " + a[3]; output += "\n Effects of passing entire array by reference"; modifyArray(a); // array a passed call-by-reference output += "\n\nThe values of the modified array are:\n"; for (int i = 0; i < a.length; i++)
output += " " + a[i]; System.out.println(output);
} public static void modifyArray(int b[]) {
for (int j = 0; j < b.length; j++)
b[j] *= 2;
} public static void modifyElement(int e) {
e *= 2;
} }

输出结果截图:

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAdEAAACzCAIAAABZ6rEpAAARI0lEQVR4nO2d26GrOAxFqYsOphHq4fc2QjMpJvNxAvgh2XIwCiFr/cwdDrbl145ssBieAADgxfBpAwAAfoiy5i7TMC0udizT8IdTeQKPeXzZMM6PloR+rfR8vsw0lWe/M+MC3QFwT16au+vNEOqOr5o8H/P4uUm+TDatzY28oeZu6dFcgL4kfm4iHz+kueayP625fqC5AP0xaO66zty9wMArLszJxzyGnuPmR27r1ix5MskDY8K/iKUHFyveapY88/HVOmV3bhV6v5W0O5dpmObt+uuyvOQPG3RIGzlpzy3LzU5zd8iIyTXjCzWKuiNuxEKH2ktXu2OZ6h0E0I+q5q7jcZmCf4XDuzwjwqmdDex0Uls0Vy7d6mqGUzif3O/7uQdaSTFpmXZdjGuXt1JwX1ROfmduZ6FmjX5ucLtovF6jJHlQDbsJldL17kBzwRfz3sI2plNnr+RWbqM7mjuRX9aouUrpr8u1qaMX0Glvob2VNJP0X5EjmiutG6zdoSAlF42X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/LtemTkFv+uwttLfSmuLVVH+aK9sZakUvzRXtLBWUIfWm+BMo/y4qybdhU1m1GEtvGbQAp9KuudZnTWuqXUm2PDUvxqC5Vce6qLx+mmtupQ9rrmhng+bKvWnWXGUwvMZLdfViLr1p0AKcSbvmhgvPOo95HOclkNxg1Zyt6nKp2b3kfPWuFlgR3YN7C/n8PdRKoubKdu4XwwZRzTfvLYheoVaQdmfUm1bN1QfDMo3zXJPchtL17mBvAXx5Q3PjlVrVfcjG9LYcDGZVuvZLrkbzTyjd/MQnLD42veH5/F5a8Azt3VaSNVexc8tyWpZy00k1Uu6U7JQKqjRn2Ef2vQUx+faHaofYS1e7A80FXziHBpeE3QC4KWguXJCm/SuAbwLNhWvxt12Ajwt3Bc0FAPADzQUA8APNBQDwA80FAPCjn+amb612zrjnU+zgrc4+luphew4gnWc+rZEBwIdemvuYx+AV+46CsEzDOE394gl2Nu/5bAn605SneAY4PMjAy1QA38cJews9360Uped4hl2y2oiPoPbMXo2N0N/3BwAX+mvuCQLZL8s1/EP39flrd6GzCkYVD+Pn/J11ZX8B4Ovorbkdndx9yd5Vc6PYql1Uaw2BG0du7YGguVsDczgW4Bvpqbm79vTKLOG4xsQBWa2Rzqt5Rvu5HZ3dbG8hjkLD3gLA19FNc7sKrpB3p6yDrHo9TdPjQ3bJWgpuSUACgG+lk+ZmXmlXPejq0wWmnuGT99tYKcddZF8B4CvhTAQAgB9oLgCAH2guAIAfaC4AgB9oLgCAH2guAIAfaC4AgB9oLgCAH2guAIAfaC4AgB9oLgCAH2guAIAfaC4AgB9oLgCAH2guAIAfaC4AgB9oLgCAH2guAIAfaC4AgB9oLgCAH2guAIAfaC4AgB9oLgCAH2guAIAfaC4AgB9oLgCAH2guAIAfaC4AgB9oLgCAH2guAIAfaC4AgB9oLgCAH2guAIAf/wMp+VvQ5RB7xwAAAABJRU5ErkJggg==" alt="" />

分析:

按引用传递与按值传送数组类型方法参数的最大关键在于:
使用前者时,如果方法中有代码更改了数组元素的值,实际上是直接修改了原始的数组元素。
使用后者则没有这个问题,方法体中修改的仅是原始数组元素的一个拷贝。
例子二:数组之间的赋值:

源代码:

public class ArrayInRam {
public static void main(String[] args) {
// 定义并初始化数组,使用静态初始化
int[] a = { 5, 7, 20 };
System.out.println("a数组中的元素:");
// 循环输出a数组的元素
for (int i = 0; i < a.length; i++) {
System.out.print(a[i] + ",");
}
// 定义并初始化数组b,使用动态初始化
int[] b = new int[4];
// 输出b数组的长度
System.out.println("\nb数组的初始长度为:" + b.length);
// 因为a是int[]类型,b也是int[]类型,所以可以将a的值赋给b。
// 也就是让b引用指向a引用指向的数组
b = a;
System.out.println("b=a,赋值之后,b数组的元素为:");
// 循环输出b数组的元素
for (int i = 0; i < b.length; i++) {
System.out.print(b[i] + ",");
} // 再次输出b数组的长度
System.out.println("\n赋值之后,b数组的长度为:" + b.length);
}
}

实验结果截图:

分析:

代码中b=a;表示将数组a赋值给b,则之后输出的b的长度就等于a的长度。

例子三:利用二维数组和循环语句绘制五子棋盘

源代码:

import java.io.*;

public class QiPan
{
//定义一个二维数组来充当棋盘
private String[][] board;
//定义棋盘的大小
private static int BOARD_SIZE = 15;
public void initBoard()
{
//初始化棋盘数组
board = new String[BOARD_SIZE][BOARD_SIZE];
//把每个元素赋为"╋",用于在控制台画出棋盘
for (int i = 0 ; i < BOARD_SIZE ; i++)
{
for ( int j = 0 ; j < BOARD_SIZE ; j++)
{
board[i][j] = "╋";
}
}
}
//在控制台输出棋盘的方法
public void printBoard()
{
//打印每个数组元素
for (int i = 0 ; i < BOARD_SIZE ; i++)
{
for ( int j = 0 ; j < BOARD_SIZE ; j++)
{
//打印数组元素后不换行
System.out.print(board[i][j]);
}
//每打印完一行数组元素后输出一个换行符
System.out.print("\n");
}
}
public static void main(String[] args)throws Exception
{
QiPan gb = new QiPan();
gb.initBoard();
gb.printBoard();
//这是用于获取键盘输入的方法
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String inputStr = null;
System.out.println("请输入您下棋的座标,应以x,y的格式:");
//br.readLine():每当在键盘上输入一行内容按回车,刚输入的内容将被br读取到。
while ((inputStr = br.readLine()) != null)
{
//将用户输入的字符串以逗号(,)作为分隔符,分隔成2个字符串
String[] posStrArr = inputStr.split(",");
//将2个字符串转换成用户下棋的座标
int xPos = Integer.parseInt(posStrArr[0]);
int yPos = Integer.parseInt(posStrArr[1]);
//把对应的数组元素赋为"●"。
gb.board[xPos - 1][yPos - 1] = "●";
/*
电脑随机生成2个整数,作为电脑下棋的座标,赋给board数组。
还涉及
1.座标的有效性,只能是数字,不能超出棋盘范围
2.如果下的棋的点,不能重复下棋。
3.每次下棋后,需要扫描谁赢了
*/
gb.printBoard();
System.out.println("请输入您下棋的座标,应以x,y的格式:");
}
}
}

实验结果截图:

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAWQAAAE2CAIAAADZP3+LAAAJMUlEQVR4nO3b25HbSBZFUdgFD9qRtCetSWfSGMwHARAgi9JVqKQ53bHWx8SoLouPamIzicey3Yy2tLF96dtGy7L8tcf6T4wgwnL/p1gEjiCCWOSPIIJY5I8gwrJtW1s++eef7xtt27ZtYzxjsW3b9oce698/Eg7i/B9WFka/OIIIYpE/gghikT+CCGKRP4IIy89vAiAWQJFYACViAZSIBVAiFkCJQ6f5I4ggFvkjiCAW+SOIIBb5I4jw9y5RN/qVkXAQx8oifwQRxCJ/BBHEIn8EEcQifwQRnMEJlIgFUCIWQIlYACViAZSIBVDi0Gn+CCKIRf4IIohF/ggiiEX+CCK4RD1zJBzEsbLIH0EEscgfQQSxyB9BBLHIH0EEZ3ACJWIBlIgFUCIWQIlYACViAZQ4dJo/gghikT+CCGKRP4IIYpE/ggguUc8cCQdxrCzyRxBBLPJHEEEs8kcQQSzyRxDBGZxAiVgAJWIBlIgFUCIWQIlYACUOneaPIIJY5I8ggljkjyCCWOSPIIJL1DNHwkEcK4v8EUQQi/wRRBCL/BFEEIv8EURwBidQIhZAiVgAJWIBlIgFUCIWQIlDp/kjiCAW+SOIIBb5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LjxIzgobvwIDoobP4KDxxpjRpT4AiNu/AgOihs/goPixo/goLjxIzi4c4aUKC5SorhIieIiJYqLlCguUuJyWPwIDoobP4KD4saP4KC48SM4eKwxZkSJLzDixo/goLjxIzgobvwIDoobP4KDO2dIieIiJYqLlCguUqK4SIniIiUuh8WP4KC48SM4KG78CA6KGz+Cg8caY0aU+AIjbvwIDoobP4KD4saP4KC48SM4uHOGlCguUqK4SIniIiWKi5QoLlLiclj8CA6KGz+Cg+LGj+CguPEjOHisMWZEiS8w4saP4KC48SM4KG78CA6KGz+CgztnSIniIiWKi5QoLlKiuEiJ4iIlLofFj+CguPEjOChu/AgOihs/goPHGmNGlPgCI278CA6KGz+Cg+LGj+CguPEjOLhzhpQoLlKiuEiJ4iIliouUKC5S4nJY/AgOihs/goPixo/goLjxIzh4rDFmRIkvMOLGj+CguPEjOChu/AgOihs/goM7Z0iJ4iIliouUKC5SorhIieIiJS6HxY/goLjxIzgobvwIDoobP4KDxxpjRpT4AiNu/AgOihs/goPixo/goLjxIzi4c4aUKC5SorhIieIiJYqLlCguUuJyWPwIDoobP4KD4saP4KC48SM4eKwxZkSJLzDixo/goLjxIzgobvwIDoobP4KDO2dIieIiJYqLlCguUqK4SIniIiUuh8WP4KC48SM4KG78CA6KGz+Cg8caY0aU+AIjbvwIDoobP4KD4saP4KC48SM4uHOGlCguUqK4SIniIiWKi5QoLlLiclj8CA6KGz+Cg+LGj+CguPEjOHisMWZEiS8w4saP4KC48SM4KG78CA6KGz+CgztnSIniIiWKi5QoLlKiuEiJ4iIlLofFj+CguPEjOChu/AgOihs/goPHGmNGlPgCI278CA6KGz+Cg+LGj+CguPEjOLhzhpQoLlKiuEiJ4iIliouUKC5S4nJY/AgOihs/goPixo/goLjxIzh4rDFmRIkvMOLGj+CguPEjOChu/AgOihs/goM7Z0iJ4iIliouUKC5SorhIieIiJYqLlKbimqwXEac/t9b2mUmp2rZfYHJyY92kavvQ5cmmdflaU23DMDRV203W0LROfxu/+uwn+2kfms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69RsfRHH/tHHYfIRB8a4oLlKiuEiJ4iIliouUKC5SorhIieIiJYqLlP4FaKEDGHiz1koAAAAASUVORK5CYII=" alt="" />

例子四:将整数转换为汉字读法字符串(比如“1123”转换为“一千一百二十三”)

源代码:

package hanzidufa;

public class Num2Rmb
{
private String[] hanArr = {"零" , "一" , "二" , "三" , "四" ,
"五" , "六" , "七" , "八" , "九"};
private String[] unitArr = {"十" , "百" , "千","万","十万","百万"}; /**
* 把一个四位的数字字符串变成汉字字符串
* @param numStr 需要被转换的四位的数字字符串
* @return 四位的数字字符串被转换成的汉字字符串。
*/
private String toHanStr(String numStr)
{
String result = "";
int numLen = numStr.length();
//依次遍历数字字符串的每一位数字
for (int i = 0 ; i < numLen ; i++ )
{
//把char型数字转换成的int型数字,因为它们的ASCII码值恰好相差48
//因此把char型数字减去48得到int型数字,例如'4'被转换成4。
int num = numStr.charAt(i) - 48;
//如果不是最后一位数字,而且数字不是零,则需要添加单位(千、百、十)
if ( i != numLen - 1 && num != 0)
{
result += hanArr[num] + unitArr[numLen - 2 - i];
}
//否则不要添加单位
else
{ //上一个数是否为“零”,不为“零”时就添加
if(result.length()>0 && hanArr[num].equals("零") && result.charAt(result.length()-1)=='零')
continue;
result += hanArr[num];
}
}
//只有个位数,直接返回
if(result.length()==1)
return result; int index=result.length()-1;
while(result.charAt(index)=='零'){
index--;
}
if(index!=result.length()-1)
return result.substring(0,index+1);
else {
return result;
}
} public static void main(String[] args)
{
Num2Rmb nr = new Num2Rmb();
System.out.println("只支持整数(0~百万)");
//测试把一个四位的数字字符串变成汉字字符串
System.out.println(nr.toHanStr("0"));
System.out.println(nr.toHanStr("1"));
System.out.println(nr.toHanStr("10"));
System.out.println(nr.toHanStr("15"));
System.out.println(nr.toHanStr("110"));
System.out.println(nr.toHanStr("123"));
System.out.println(nr.toHanStr("105"));
System.out.println(nr.toHanStr("1000"));
System.out.println(nr.toHanStr("1100"));
System.out.println(nr.toHanStr("1110"));
System.out.println(nr.toHanStr("1005"));
System.out.println(nr.toHanStr("1105"));
System.out.println(nr.toHanStr("1111"));
System.out.println(nr.toHanStr("10000"));
System.out.println(nr.toHanStr("10001"));
System.out.println(nr.toHanStr("10011"));
System.out.println(nr.toHanStr("10111"));
System.out.println(nr.toHanStr("11111"));
System.out.println(nr.toHanStr("11000"));
System.out.println(nr.toHanStr("11100"));
System.out.println(nr.toHanStr("11110"));
System.out.println(nr.toHanStr("101110"));
System.out.println(nr.toHanStr("1001110")); }
}

实验结果截图:
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAfIAAAHnCAIAAADM6EivAAAPOklEQVR4nO3dwXaruBZF0fz/T+c13hgxdW1jIaSDvJmziYlE3caKSjHw8wtAkJ+rLwCAkWQdIIqsA0SRdYAosg4QRdYBogzL+s+P3xAA15N1gCiyDhBF1gGiyDpAlM4W/7QZe60AfPQo78lSizjACmzCAESRdYAosg4QRdYBosg6QBRZB4gi6wBRtBggiqwDRJF1gCiyDhBF1gGiyDpAFFkHiCLrAFHcjgQQpSjr3qMEUOOC1bqIA8wj6wBRZB0gSmdhz7zPWtYB5nkU9kypf8/9yXTkfxDAvVVvwjyfJusAA8k6QBRZB4hSmvWX58g6wECyDhBF1gGiVGT95FcnAWgnpgBRZB0giqwDRJF1gCiyDhBF1gGiyDpAFFkHiNKf9bI7jNypBNDugpferTMyQJ4vWFDLOkC7AcWcnV1ZB2h3qpg1j+6SdYB2Z7Pe8dHHMT3uEaDbo48dPW3M+slSizhAu+VW61OHAohnbx0gitU6QBRZB4gi6wBR7K0DRLFaB4iimABRZB0giqwDRJF1gCiyDhBF1gGiyDpAFFkHiNKf9TOPUD860ZBxAO7gC+4F3R+55lcLwLcoWlCfia80A7QbUMzZ2ZV1gHae4AgQZbknOH7crrFjDrDj0ceOns7I+tShAOItt1rvGMqiHuCPvXWAKAmrdQD+yDpAFFkHiFKxt/7x2zX7e/GyDtDuu1frJ39hAOSRPIAosg4QRdYBosg6QBRZB4gi6wBRZB0giqwDROnP+tH7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BRZB4gi6wBRZB0giqwDRJF1gCiyDhBF1gGiyDpAFFkHiCLrAFFkHSCKrANEkXWAKLIOEEXWAaLIOkAUWQeIIusAUWQdIIqsA0SRdYAo/wM7FRwg9elFjwAAAABJRU5ErkJggg==" alt="" />

例子五:将数字表示金额“汉字表达法”

源代码:

package hanzidufa;

public class Num2Rmb
{
private String[] hanArr = {"零" , "壹" , "贰" , "叁" , "肆" ,
"伍" , "陆" , "柒" , "捌" , "玖"};
private String[] unitArr = {"分","角","元","十","百","千","万","十万","百万"}; /**
* 把一个四位的数字字符串变成汉字字符串
* @param numStr 需要被转换的四位的数字字符串
* @return 四位的数字字符串被转换成的汉字字符串。
*/
String toHanStr(String numStr)
{
String result = "";
int numLen = numStr.length();
int flag;
flag=numStr.indexOf('.');
String numStr1,numStr2;
numStr1=numStr.substring(0,flag);
numStr2=numStr.substring(flag+1,numLen);
int numLen1=numLen-flag;
int numLen2=2;
//依次遍历数字字符串的每一位数字
for (int i = 0 ; i < numLen1 ; i++ )
{
//把char型数字转换成的int型数字,因为它们的ASCII码值恰好相差48
//因此把char型数字减去48得到int型数字,例如'4'被转换成4。
int num = numStr1.charAt(i) - 48;
//如果不是最后一位数字,而且数字不是零,则需要添加单位(千、百、十) result += hanArr[num] + unitArr[numLen - 2 - i];
}
//只有个位数,直接返回
for(int j=0;j<2;j++)
{
int num1=numStr2.charAt(j)-48;
result += hanArr[num1] + unitArr[1 - j];
}
return result;
} public static void main(String[] args)
{
Num2Rmb nr = new Num2Rmb();
System.out.println("只支持整数(0~百万)");
//测试把一个四位的数字字符串变成汉字字符串
System.out.println(nr.toHanStr("123.11")); }
}

实验结果截图:

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAVEAAACHCAIAAAAgBP2TAAADOUlEQVR4nO3Y0W7jNhRAQf//T6cPBYJuLFOXdJIWPTNPiUxTlMAjbfbxAZQ8/u0FAL9K89Cyav7xuPn01v3pXwx7Pjic7XbMseHkB2s4mPlHr5T/tz+20TsZn+3Cv781Kfx2/mESw0s7uxvHYyb3eXiBsHb+np+PPNjll78uznKZ1nDxQ7cTHq9hMuwXLpCIvZfb9RRvbL7b1+DH4P22u+D52o4fUq+WejDzwfyw8INV3I78eL1xP4/v7vXH3QPiJ3xey1bGu/PPj8PCW3/PL/bccDuud/NlS8fn3brAN+/G+qOtmRdXdPspPNt7Ky628mLkYlu/mmG4lQ/KvFze2QKOm5/P/Lh66n25LtmzZeN/lS++/JPv+d2tvNXVcPDu3ZiP35r5cp1S58x/7u/5L18fVnE5z3rlw5Fzizm/5RSa51v80nt+0eR65knMn4+P2wfKcG3//Ojsbkwufz7z7rJhYfp6/K7mX/1wO/5y5nUkrwZsNT8/vsh48uTaPa55zvz2e/57m18ve7Kwj6eHyO20B8+Ry/Fv3mfNc+Y+jHXYB3v3+dPLI4tTjK9udV2XB88GPB+/bf545tvjsPb138m3/vjyznt+WMWXEz2f4nLmyYLXq30+7/xuTGaeL/h25i8TwhZbB1o0Dy2ahxbNQ4vmoUXz0KJ5aNE8tGgeWjQPLZqHFs1Di+ahRfPQonlo0Ty0aB5aNA8tmocWzUOL5qFF89CieWjRPLRoHlo0Dy2ahxbNQ4vmoUXz0KJ5aNE8tGgeWjQPLZqHFs1Di+ahRfPQonlo0Ty0aB5aNA8tmocWzUOL5qFF89CieWjRPLRoHlo0Dy2ahxbNQ4vmoUXz0KJ5aNE8tGgeWjQPLZqHFs1Di+ahRfPQonlo0Ty0aB5aNA8tmocWzUOL5qFF89CieWjRPLRoHlo0Dy2ahxbNQ4vmoUXz0KJ5aNE8tGgeWjQPLZqHFs1Di+ahRfPQonlo0Ty0aB5aNA8tmocWzUOL5qFF89CieWjRPLRoHlo0Dy2ahxbNQ4vmoUXz0KJ5aNE8tGgeWjQPLZqHFs1Di+ahRfPQonlo0Ty0aB5aNA8tmocWzUOL5qFF89DyF/xAmxyReevkAAAAAElFTkSuQmCC" alt="" />

例子六:利用数组储存大数字,并实现阶乘运算

源代码:

    import java.util.Scanner;  

    public class BignumberJiecheng {
private static int[] resultArray = new int[10000000]; static int resultJinwei = 0;
static long index = 0; public static void main(String[] args) {
System.out.println("请输入要求阶乘的N的值:");
Scanner sin = new Scanner(System.in);
int number = sin.nextInt();
long maxIndex = method(number);
System.out.println("阶乘为:");
for (long i = maxIndex-1; i >= 0; i--) {
System.out.print(resultArray[(int) i]);
if(i % 100 == 0) { //此处对输出格式做处理时因为eclipse编译器的控制台每行输出的长度有限定,所以处理成每行输出100个数
System.out.println();
}
}
} public static long method(long number) {
long maxIndex = 1;
int temp = 0;
//int tempMaxIndex = 0;
resultArray[0] = 1;
for (long i = 1; i <= number; i++) {
for (long j = 0; j < maxIndex; j++) {
resultArray[(int) j] *= i;
resultArray[(int) j] += resultJinwei;
temp = resultArray[(int) j];
if (temp >= 10) {
resultArray[(int) index] = temp % 10;
resultJinwei = temp / 10;
index++;
if(maxIndex<index+1)
maxIndex = index+1; } else {
index++;
resultJinwei = 0;
}
}
index = 0; }
return maxIndex;
} }

实验截图:

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAUkAAABtCAIAAACjogRrAAAH7klEQVR4nO2dPXKkPBBAORcHmlv4DgQ+hQ8wuTPHW7URqaOt2tQpXwAz6Ke71cCMP7b9Xm1tzSCpkUBPCIFrugkAItL93xUAgKeA2wAxWd3uOsFzcePWzJsyeNgd/2ARuwLF9h2V2RfqgfuFSMjdomlU3YHmLcf1FnM6S6X1F1PrttgjhXNMEUNJ+a+Xruu67nItNqUbnKF2Zoafg8vYemPR3f0efo/bYpG6ts7xyJNH3F11oBa3u34Yb9lqt32hssziWOwZjyAw6vTS7iVOi7TgdqqNP2edv/lhd+Riu3K4rpeu6/q+T2wu3HaHUg9mvQV+Jnum0LUwzR7ZjFmn2lrujmz43Cxl57l/1n2bRR6GRO7abV+oMoM9+sAPpOwZk9JLim40Oa4PWky77Ca3d3w1KlBrU1RYKytWVcpwE/l6uc/LbbeNStpDlVYcfg57lmHqfl9fKOzPtts2df7m52KL8UGsT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ADHBbYCY4DZATHAbICa4DRAT3AaICW4DxAS3AWKC2wAxwW2AmPwHWaRTSvzT8koAAAAASUVORK5CYII=" alt="" />

例子七:随机生成10个数(1~10),输出数组内容,并输出数组的和。

源代码:

package sjs;

public class sjsj {

	public static void main(String[] args) {
// TODO Auto-generated method stub
int a[]=new int [10];
int sum=0;
for(int i=0;i<10;i++)
{
a[i]=1+(int)(Math.random()*10);
sum+=a[i];
}
for(int j=0;j<10;j++)
{
System.out.println(a[j]); }
System.out.print("数组之和为:"+sum); } }

实验结果截图:

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAASoAAAEWCAIAAABe4E2uAAAG20lEQVR4nO3dUZaiOACGUdblDmYjrsfVuBkXYz+IQiCAWp38c7rufeiusdSyz+GbUEDCcAdChvQHgN9LfhBTye96HoZhGIbztf/Hgd9kld8zPvlBa4v8rudhGM7X8a/MR4LfosjvVZ38oINZfrPm5AcdvPIripMfdDDmt+hNftDBcL/f77fLqaxNftDBcB/r2yJCaKV+1YvRDzqQH8TID2Jccg0x8oMY+UGM/CBGfhAjP4iRH8TID2LkBzHyg5hyum3hdLklPxn884r8BAc9yQ9i5Acx8oOYrUMvSoTmqicexsVfzLeFpjbO+z0C1B+0tHXa/Xq2BwqN7Y1+6oOmavk99jzFB4098ysPfEoPOnDJNcTID2LkBzHygxj5QYz8IEZ+ECM/iJEfxMgPYh75rZc5c2d3aG5z9HODW2jNhCOI2bm3u/qgrWp+djyhh0p+djyhj3V+hj7oZJmfoQ+6WeTnmAv0U+RndU/oaZ6foQ+6mvIz9EFnLrmGGPlBjPwgRn4QIz+IkR/EyA9i5Acx8oMY+UHMLL/HVWfurwm9FHe3fV3wacotdDBb57PI7Xo2BEJjw/1eneJ+u5yMf9DWNPotxjrDH7Q2/u63mGk7HoWRH7Q0Hfmc3+fhdLlacgla2zrv53c/aM49HiBm5x4Pxj5oa2OVayMftFdc9eKemtCTS64hRn4QIz+IkR/EyA9i5Acx8oMY+UGM/CBGfhBTye95/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T++dLDzuRXY+rtfbPc7T/sro9+P8ptFtuhtOR3Sziff2jviUg1yeuXnhbz5nK0ReOeFHz34xscriqsPd4/kTE3mB97dsvcb+DS//ScshtCP8tvpdv7m+x/vaG/zfn8lWPkOvOt473Gd3/qZH+X3znd3Bt7DgW5/h/nY4sBmJb/57qZFGfne5lGNxYNvjlfretfPPPhAR2c+9neDt/4V75uGtYrztXKgxaqMfGk5pr2+Lp704c7k1vPff5+dwfYwv/3H9//vUFWOfusjLfLjS5VN+aPt+839w083+vdHv09H2h/nN56KfwVo75OvVU673Y92Ptej0JuFvL/p//xp3+15Vq0PvbghBn/FZhhbHVbeYsPWq3aefPiz3nnOF+MbRNhMIUZ+ECM/iJEfxMgPYuQHMfKDGPlBjPwgRn4QIz+IkR/EyA9i5Acx8oMY+UGM/CBGfhAjP4iRH8TID2LkBzHygxj5QYz8IEZ+ECM/iJEfxMgPYuQHMfKDGPlBjPwgRn4QIz+IkR/EyA9i5Acx8oMY+UGM/CBGfhDzB7SCzcMqK2LwAAAAAElFTkSuQmCC" alt="" />

JAVA中数组总结(课堂总结)的更多相关文章

  1. java中数组的相关知识

      1. 2.数组的命名方法 1)int[]ages=new int[5]; 2) int[]ages; ages=new int[5]; 3)int[]ags={1,2,3,4,5}; 4)int[ ...

  2. Java中数组的特性

    转载:http://blog.csdn.net/zhangjg_blog/article/details/16116613 数组是基本上所有语言都会有的一种数据类型,它表示一组相同类型的数据的集合,具 ...

  3. 在java 中&comma;数组与 List&lt&semi;T&gt&semi; 类型的相互转换

    在java中,数组与List<T> 之前进行互相转换,转换方法可总结为以下几种: 一. 将 数组转换成List<T> 1. 使用 Collections 的addAll 方法 ...

  4. Java中数组的初始化方式

    Java中数组的初始化方式    初始化方式有两种: 1.静态初始化:初始化时由程序猿显式指定每一个数组元素的初始值,由系统指定数组长度 2.动态初始化:初始化时由程序猿仅仅指定数组长度,由系统为数组 ...

  5. java中数组复制的两种方式

    在java中数组复制有两种方式: 一:System.arraycopy(原数组,开始copy的下标,存放copy内容的数组,开始存放的下标,需要copy的长度); 这个方法需要先创建一个空的存放cop ...

  6. Java中数组的插入,删除,扩张

    Java中数组是不可变的,但是可以通过本地的arraycop来进行数组的插入,删除,扩张.实际上数组是没变的,只是把原来的数组拷贝到了另一个数组,看起来像是改变了. 语法: System.arrayc ...

  7. java中数组、集合、字符串之间的转换,以及用加强for循环遍历

    java中数组.集合.字符串之间的转换,以及用加强for循环遍历: @Test public void testDemo5() { ArrayList<String> list = new ...

  8. Java 中数组的内存分配

    Java 中数组的内存分配 1.Java 程序在运行时,需要在内存中分配空间.为了提高运算效率,就对空间进行了不同区域的划分,因为每一片区域都有特定的处理数据和内存管理方式. 2.数组基本概念 数组是 ...

  9. 将java中数组转换为ArrayList的方法实例(包括ArrayList转数组)

    方法一:使用Arrays.asList()方法   1 2 String[] asset = {"equity", "stocks", "gold&q ...

  10. 【Java面试题】18 java中数组有没有length&lpar;&rpar;方法?string没有lenght&lpar;&rpar;方法?下面这条语句一共创建了多少个对象:String s&equals;&quot&semi;a&quot&semi;&plus;&quot&semi;b&quot&semi;&plus;&quot&semi;c&quot&semi;&plus;&quot&semi;d&quot&semi;&semi;

    数组没有length()这个方法,有length的属性.String有有length()这个方法. int a[]; a.length;//返回a的长度 String s; s.length();// ...

随机推荐

  1. gulp的基本使用

    gulp 了解 首先我们了解一下什么是gulp, gulp是前端自动化构建工具,在开发过程中很多重复的任务,我们都可以正确的使用gulp来完成,gulp基于nodejs,使用gulp可以做很多事情 例 ...

  2. &lbrack;SQL Server 系&rsqb; -- 模糊查询

    SQL Server中的通配符有下面四种 通配符 说明 % 包含零个或多个字符的任意字符串 _(下划线) 任意单个字符 [ ] 任意在指定范围或集合中的单个字符 [^ ] 任意不在指定范围或集合中的单 ...

  3. IOS调用相机相册

    #import "SendViewController.h"  //只能打开,没有加载图片的代码,老代码,供参考 #import <MobileCoreServices/UT ...

  4. ionic3使用echarts

    1.安装typings及echarts npm install typings echarts --global 2.安装 ECharts 的 TypeScript 定义文件 npm install ...

  5. mysql5&period;7 参数记录 (持续更新)

    sync_binlog 控制数据库的binlog刷到磁盘 默认sync_binlog=1,表示每次事务提交,MySQL都会把binlog刷下去,是最安全但是性能损耗最大的设置. sync_binlog ...

  6. Ubuntu18&period;04安装网易云音乐

    一. 安装 去网易云官网下载对应于ubuntu系统的安装包 安装依赖 dpkg -s libcanberra-gtk-module #检查依赖是否安装 sudo apt install libcanb ...

  7. ios中输入框的父类--文本框,DataPick,pickerview

    父控制器 #import <UIKit/UIKit.h> #import "ScrollViewExt.h" @interface BaseKeyBoardCtrl : ...

  8. 微信小程序制作家庭记账本之七

    最后一天,程序完成的仍然不是很好,作品很简陋,不过还是可以记账的,没有购买域名,别人无法使用,下次我会完成的更好.

  9. CentOS 7 firewalld vsftpd开放端口

    开放FTP端口的方法: 暂时开放 ftp 服务 firewall-cmd --add-service=ftp 1 永久开放 ftp 服务 firewall-cmd --add-service=ftp ...

  10. Android Support Library 23&period;2介绍(翻译自官方文档)

    Android Support Library 23.2 (译者注:本文标注了部分文字链接,但须要***,要查看全部链接.请查看sukey=014c68f407f2d3e181b6b5e665f26a ...