package work5;
import java.util.Scanner;
public class Dwork {
public static void main(String[] args) {
// TODO Auto-generated method stub
int count=0;
Scanner sc=new Scanner(System.in);
System.out.print("请输入一个字符串(由数字和字符组成):");
String str=sc.nextLine();
if(!str.matches("[0-9A-Za-z]*"))
System.out.println("字符串只能由数字和字母组成");
else{
char[] chs=str.toCharArray();
for(int i=0;i<str.length();i++){
if(chs[i]>='0' &&chs[i]<='9')
count++;
}
System.out.print("该行字符中的数字个数为:"+count);
}
}
}
package work5;
import java.util.Scanner;
public class Dwork1 {
public static void main(String[] args) {
// TODO Auto-generated method stub
int[] a=new int[100];
int t=0,k=0;
Scanner sc=new Scanner(System.in);
System.out.print("请输入n:");
int n=sc.nextInt();
System.out.print("请输入m(m>=3):");
int m=sc.nextInt();
for(int i=0;i<n;i++)
a[i]=2*(i+1);
System.out.print("该数列的平均值序列为:");
for(int i=0;i<n/m;i++)
{
for(int j=0;j<m;j++)
t=t+a[i*m+j];
System.out.print(t/m+" ");
}
if(n%m!=0)
for(int i=0;i<n%m;i++)
k=k+a[n-n%m+i];
System.out.println(k/m+" ");
}
}
package work5;
import java.util.Scanner;
public class Dwork2 {
public static void main(String[] args) {
// TODO Auto-generated method stub
int min=0,k=0,t=0;
int[] arr=new int[20];
Scanner sc=new Scanner(System.in);
System.out.println("请输入20个整数(用空格分隔):");
for(int i=0;i<arr.length;i++)
arr[i]=sc.nextInt();
min=arr[0];
for(int i=0;i<arr.length;i++)
if(arr[i]<min){
min=arr[i];
k=i;
}
if(k!=0)
{
t=arr[k];
arr[k]=arr[0];
arr[0]=t;
}
for(int a:arr) {
System.out.print(a+" ");
}
}
}