import java.util.Scanner;
public class One_1 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("请输入一行文字:");
String arr = input.nextLine();
int num = 0;
int alp = 0;
int spa = 0;
int oth = 0;
for (int i = 0; i < arr.length(); i++) {
char ch = arr.charAt(i);
if(ch >= '0' && ch <= '9') {
num++;
} else if((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z')) {
alp++;
} else if(ch == ' ') {
spa++;
} else {
oth++;
}
}
System.out.println("数字个数:"+num);
System.out.println("英文字母个数:"+alp);
System.out.println("空格个数:"+spa);
System.out.println("其它字符个数:"+oth);
}
}
package Test;
import java.util.Arrays;
import java.util.Scanner;
public class One_2 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("请输入十个整数:");
int[] num = new int[10];
for (int i = 0; i < num.length; i++) {
num[i] = input.nextInt();
}
Arrays.sort(num);
System.out.println("十个整数排序的结果:");
for (int j = 0; j < num.length; j++) {
System.out.print(num[j]+",");
}
}
}
package Test;
import java.util.Scanner;
public class One_3 {
public static void main(String[] args) {
Scanner ipnut = new Scanner(System.in);
int[] arr1 = {10,20,30};
int[] arr2 = {40,50,60};
int[] arr = new int[6];
System.out.print("第一个数组中的元素:");
for (int i = 0; i < arr.length/2; i++) {
System.out.print(arr1[i]);
if (i < arr.length/2-1) {
System.out.print(",");
}
arr[i] = arr1[i];
}
System.out.println();
System.out.print("第二个数组中的元素:");
for (int j = arr.length/2; j < arr.length; j++) {
System.out.print(arr2[j-arr.length/2]);
if (j < arr.length-1) {
System.out.print(",");
}
arr[j] = arr2[j-arr.length/2];
}
System.out.println();
System.out.print("两个数组合并后:");
for (int k = 0; k < arr.length; k++) {
System.out.print(arr[k]);
if (k < arr.length-1) {
System.out.print(",");
}
}
System.out.println();
System.out.print("逆序后:");
for (int l = arr.length-1; l >= 0; l--) {
System.out.print(arr[l]);
if (l > 0) {
System.out.print(",");
}
}
}
}
package Test;
import java.util.Scanner;
public class One_4 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String[] name = new String[5];
double[] high = new double[5];
double totalHigh = 0;
double avg = 0;
for (int i = 0; i < 5; i++) {
System.out.print("请输入第"+(i+1)+"位同学的姓名、身高:");
name[i] = input.next();
high[i] = input.nextDouble();
totalHigh += high[i];
}
avg = totalHigh/5;
System.out.println("平均身高是"+avg+"米。");
}
}