import java.util.Scanner;
公司主营业务:成都做网站、网站制作、移动网站开发等业务。帮助企业客户真正实现互联网宣传,提高企业的竞争能力。创新互联建站是一支青春激扬、勤奋敬业、活力青春激扬、勤奋敬业、活力澎湃、和谐高效的团队。公司秉承以“开放、自由、严谨、自律”为核心的企业文化,感谢他们对我们的高要求,感谢他们从不同领域给我们带来的挑战,让我们激情的团队有机会用头脑与智慧不断的给客户带来惊喜。创新互联建站推出甘井子免费做网站回馈大家。
public class Test {
public static void main(String[] args) {
int num = 5;
int[] n = new int[num];
Scanner sc = new Scanner(System.in);
System.out.println("请输入"+num+"位会员的积分");
for(int i=0;inum;i++){
System.out.print("第"+(i+1)+"位会员积分:");
n[i]=sc.nextInt();
}
System.out.println("\n序号\t历史积分");
for(int i=0;in.length;i++){
System.out.println(i+1+"\t"+n[i]);
}
sc.close();
}
}
package test;
import java.util.Random;
public class Test {
public static void main(String[] args) {
int maxVal=-1;
int maxRow=-1;
int maxCol=-1;
int[][] arr=new int[5][5] ;
for(int i=0;i5;i++){
for(int j=0;j5;j++){
arr[i][j]=new Random().nextInt(100);
if(maxValarr[i][j]){
maxVal=arr[i][j];
maxRow=i;
maxCol=j;
}
System.out.print(arr[i][j]+" ");
}
System.out.println();
}
System.out.println("最大行 "+maxRow);
System.out.println("最大列 "+maxCol);
System.out.println("max number is "+maxVal);
}
}
public static void main(String[] args) {
/**
*
* (1)实现整型数组的创建要求由用户输入数组长度以及数组元素
*/
Scanner input = new Scanner(System.in);
System.out.print("请输入整型数组的长度:");
int lengthInt = input.nextInt();
int[] arrInt = new int[lengthInt];
for (int i = 0; i arrInt.length; i++) {
System.out.println("请输入第" + (i + 1) + "个元素");
arrInt[i] = input.nextInt();
}
System.out.print("整型数组:");
for (int i = 0; i arrInt.length; i++) {
System.out.print(arrInt[i] + "\t");
}
System.out.println();
/**
*
* (2)查找数组中最大值最小值以及求平均值
*/
int max = 0;
int min = arrInt[0];
double sum = 0;
for (int i = 0; i arrInt.length; i++) {
if (arrInt[i] max) {
max = arrInt[i];
}
if (arrInt[i] min) {
min = arrInt[i];
}
sum += arrInt[i];
}
double avg = sum / arrInt.length;
System.out.println("最大值:" + max);
System.out.println("最小值:" + min);
System.out.println("平均值:" + avg);
/**
*
* (3)实现数组的排序,有用户选择何种方式
*/
System.out.println("请选择排序的方式(输入数字即可):");
System.out.println("1:由小到大,2:由大到小");
int a = input.nextInt();
switch (a) {
case 1:
int i,
j,
t;
for (i = 0; i arrInt.length - 1; i++) {
for (j = 0; j arrInt.length - i - 1; j++) {
if (arrInt[j + 1] arrInt[j]) {
t = arrInt[j + 1];
arrInt[j + 1] = arrInt[j];
arrInt[j] = t;
}
}
}
break;
case 2:
int x,
y,
z;
for (x = 0; x arrInt.length - 1; x++) {
for (y = 0; y arrInt.length - x - 1; y++) {
if (arrInt[y + 1] arrInt[y]) {
z = arrInt[y + 1];
arrInt[y + 1] = arrInt[y];
arrInt[y] = z;
}
}
}
break;
default:
System.out.println("输入有误");
break;
}
for (int k = 0; k arrInt.length; k++) {
System.out.print(arrInt[k] + "\t");
}
System.out.println();
/**
*
* (4)实现数组的插入,并对插入后的数组重排序
*/
System.out.println("该数据长度为" + arrInt.length + ",插入数据后也记录最后" + "个的元素");
boolean ref = true;
do {
System.out.println("请插入元素:");
for (int i = 0; i arrInt.length; i++) {
if (i arrInt.length - 1)
arrInt[i] = arrInt[i + 1];
else
arrInt[i] = input.nextInt();
}
System.out.println("是否再插入新的元素?(是:Y,否:其他任何字符)");
if (!input.next().equalsIgnoreCase("y")) {
ref = false;
}
} while (ref);
System.out.print("插入元素后的数组:");
for (int i = 0; i arrInt.length; i++) {
System.out.print(arrInt[i] + "\t");
}
System.out.println();
/**
*
* (5)实现对某个数组的删除或者修改操作
*/
System.out.println("请选择操作:1.删除;2.修改");
int d = input.nextInt();
System.out.println("请输入要操作的元素下标:(输入0-" + (arrInt.length - 1)
+ "之内的数字即可):");
int index = input.nextInt();
System.out.println(index);
int[] arrs = new int[arrInt.length - 1];
switch (d) {
case 1:
for (int i = 0; i arrInt.length - 1; i++) {
if (i == index index arrInt.length - 1) {
arrs[i] = arrInt[index + 1];
} else if (i index index arrInt.length - 1) {
arrs[i] = arrInt[i + 1];
} else {
arrs[i] = arrInt[i];
}
}
for (int i = 0; i arrs.length; i++) {
System.out.print(arrs[i] + "\t");
}
break;
case 2:
System.out.println("请输入新的元素:");
int num = input.nextInt();
arrInt[index] = num;
for (int i = 0; i arrInt.length; i++) {
System.out.print(arrInt[i] + "\t");
}
break;
default:
System.out.println("输入有误");
break;
}
}