第五次作业

1.编写一个简单程序,要求数组长度为5,静态值为10,20,30,40,50.
public class Demon3.{
public static void main(String[]args){
int[]arr={10,20,30,40,50};
for(int i=0;i<5;i++){
System.out.println(arr[i]);
}
}
}
2.编写一个简单程序,要求数组长度为5,动态赋值10,20,30,40,50.
public class Demon3.{
public static void main(String[]args){
int[]arr=new int[5];
arr[0]=10;
arr[1]=20;
arr[2]=30;
arr[3]=40;
arr[4]=50;
System.out.println(arr[0]);
System.out.println(arr[1]);
System.out.println(arr[2]);
System.out.println(arr[3]);
System.out.println(arr[4]);
}
}
3.
public class Demon3.{
public static void main(String[]args){
double sum=0;
int[]arr={23,45,22,33,56};
}
for(int i=0;i sum+=arr[i];
}
System.out.println("和"+sum);
System.out.println("平均"+sum/text.length);
}
4.
public class Demon3.{
public static void main(String[]args){
int max=0;
int a=0 ;
int arr []={18,25,7,36,13,2,89,63}
for(int i=0;i if(arr[i]>max){
max=arr[i];
a=i;
}
System.out.println("数组中最大值为"+max);
System.out.println("最大数的下标为"+a);
}
}
5.将一个数组中的元素逆序存放(知识点:数组遍历、数组元素访问
public class Demon4.{
public static void main(String[]args){
int arr[]={1,2,3,4,5};
for (int i = 0; i < a.length/2; i++) {

int t;

t=a[i];

a[i]=a[a.length-1-i];

a[a.length-1-i]=t;

}

for (int i = 0; i < a.length; i++) {

System.out.print(a[i]);

}

}

}

你可能感兴趣的:(第五次作业)