import java.util.Random;
public class ShuZu {
public static void main(String[] args) {
intshuzu();
charshuzu();
}
//整型数组
public static void intshuzu() {
int [] arr =new int [10];
Random r = new Random();
//数组赋值
for(int i=0;i<arr.length;i++) {
int number = r.nextInt(arr.length);
arr[i]=number;
}
show(arr);
double p=pingjunshu(arr);
System.out.println("\n平均数:"+p);
}
//输出整型数组
public static void show(int arr []) {
System.out.print("[");
for(int i=0;i<arr.length;i++) {
if(i==arr.length-1) {
System.out.print(arr[i]);
}
else {
System.out.print(arr[i]+",");
}
}
System.out.print("]");
}
//平均数
public static double pingjunshu(int arr []) {
double sum=0;
for(int i=0;i<arr.length;i++) {
sum+=arr[i];
}
double pingjun=sum/arr.length;
return pingjun;
}
//输出字符型数组
public static void show(String arr []) {
System.out.print("[");
for(int i=0;i<arr.length;i++) {
if(i==arr.length-1) {
System.out.print(arr[i]);
}
else {
System.out.print(arr[i]+",");
}
}
System.out.print("]");
}
//字符数组
public static void charshuzu() {
int number=0;
char a,b,c,d;
String strings[]= {
"string","starting","strong","street","stir",
"student","soft","string"
};
//输出数组
show(strings);
//遍历数组
for(int i=0;i<strings.length;i++) {
String s=strings[i];
a=s.charAt(0);
b=s.charAt(1);
c=s.charAt(s.length()-2);
d=s.charAt(s.length()-1);
//判断
if(a=='s'&&b=='t'&&c=='n'&&d=='g') {
number++;
}
}
System.out.println("\n以st开头,以ng结尾的字符串有:"+number+"个");
}
}