//读取电话
public class ArrayTest {
public static void main(String[] args) {
int[] arr = new int[]{8,2,1,0,3};
int[] index = new int[]{2,0,3,2,4,0,1,3,2,3,3};
String tel = "";
for(int i = 0;i < index.length;i++){
tel += arr[index[i]];
}
System.out.println("联系方式:" + tel);
}
}
//解题思路:
//在遍历index数组的过程中,index数组中的每一个元素作为arr数组的下标,从arr数组中读取数据。
package edu.CS.javase.array.exer;
import java.util.Scanner;
public class ArrayExer02 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("请输入评委人数:");
int pingwei = scanner.nextInt();
System.out.print("请输入评委打分结果:");
int[] scoreArray = new int[pingwei];
for(int i = pingwei;i > 0;i--){
int scores = scanner.nextInt();
scoreArray[i-1] = scores;
}
//{5,4,6,8,9,0,1,2,7,3};
//2.保存最大最小值
int scoreMax = scoreArray[0];
int scoreMin = scoreArray[0];
double sum = 0;
//2.遍历数组
for (int i = 0; i < scoreArray.length; i++) {
//获得每一个数组元素
int score = scoreArray[i];
if (score > scoreMax) {
scoreMax = score;
}
if (score < scoreMin) {
scoreMin = score;
}
sum += score;
}
sum = (sum-scoreMax-scoreMin)/(pingwei-2);
System.out.println("平均分数是:" + sum );
System.out.println("max = " + scoreMax);
System.out.println("min = " + scoreMin);
}
}
//升级版:增加了评委人数选项,输入分数选项(int) 输入分数空格或者回车隔开
package edu.CS.javase.array.exer;
import java.util.Scanner;
public class ArrayExer04 {
public static void main(String[] args) {
//创建数组
String[] weekArray = new String[7];
weekArray[0] = "Monday";
weekArray[1] = "Tuesday";
weekArray[2] = "Wednesday";
weekArray[3] = "Thursday";
weekArray[4] = "Friday";
weekArray[5] = "Saturday";
weekArray[6] = "Sunday";
//读取输入
Scanner scanner = new Scanner(System.in);
System.out.print("请输入1-7数字:");
int number = scanner.nextInt();
if(number>0&&number<=7){
String week = weekArray[number - 1];
System.out.println("week = " + week);
}else{
System.out.println("输入错误,请重试!");
}
}
}
package edu.CS.javase.array.exer;
public class ArrayExer05 {
public static void main(String[] args) {
//System.out.println((int)'a');//97
//创建字符数组保存26个英文字母
char[] wordArray = new char[26];
for (int i = 0; i <= 25; i++) {
wordArray[i] = (char) (i + 97);
System.out.println("wordArray[" + i + "] = " + wordArray[i]);
}
//遍历字母数组显示当前元素的同时打印大写字母
for (int i = 0; i <= 25; i++) {
char word = wordArray[i];
//将当前的小写字符-32得到对应大写字母
char upperWord = (char) (word - 32);
System.out.println("小写字母" + word + "大写字母" + upperWord);
}
}
}
package edu.CS.javase.array.exer;
import java.util.Scanner;
public class ArrayExer06 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
//输入本组人数
System.out.print("请输入本组人数:");
int persons = scanner.nextInt();
//name数组保存名字
String[] names = new String[persons];
//score数组保存分数
double[] scores = new double[persons];
for (int i = 0; i < persons; i++) {
System.out.print("请输入姓名:");
String name = scanner.next();
names[i] = name;
System.out.print("请输入分数:");
double score = scanner.nextDouble();
scores[i] = score;
}
double maxscore = scores[0];
String maxname = names[0];
double minscore = scores[0];
String minname = names[0];
for (int i = 0; i < persons; i++) {
if(maxscore < scores[i]){
maxscore = scores[i];
maxname = names[i];
}
if(minscore > scores[i]) {
minscore = scores[i];
minname = names[i];
}
}
System.out.println("maxname = " + maxname);
System.out.println("minname = " + minname);
}
}
package edu.CS.javase.array.exer;
import java.util.Scanner;
public class ArrayExer07 {
public static void main(String[] args) {
//根据用户输入创建数组对象
Scanner scanner = new Scanner(System.in);
System.out.print("请输入学生人数:");
int studentCount = scanner.nextInt();
//根据输入人数创建数组对象
int[] scoreArray = new int[studentCount];
//将输入的学生成绩保存到数组中
for (int i = 0; i < studentCount; i++) {
//输入成绩
System.out.print("请输入第"+ (i+1) +"个学生的成绩:");
int score = scanner.nextInt();
//存入成绩
scoreArray[i] = score;
}
//找最高分
int maxscore = scoreArray[0];
for (int i = 0; i < studentCount; i++) {
if(maxscore < scoreArray[i]){
maxscore = scoreArray[i];
}
}
System.out.println("最高成绩是:" + maxscore);
//输出等级
for (int i = 0; i < scoreArray.length; i++) {
int score = scoreArray[i];
if(score > maxscore-10){
System.out.println("第" + (i+1) + "位学生的成绩" + score + "是A级");
}else if(score > maxscore-20){
System.out.println("第" + (i+1) + "位学生的成绩" + score + "是B级");
}else if(score > maxscore-30){
System.out.println("第" + (i+1) + "位学生的成绩" + score + "是C级");
}else{
System.out.println("第" + (i+1) + "位学生的成绩" + score + "是D级");
}
}
}
}