定义一个长度为10的整型数组,其值为{21,45,38,66,73,14,55,99,85,10},求其最大值

定义一个长度为10的整型数组,其值为{21,45,38,66,73,14,55,99,85,10},求其最大值。
要求;
画流程图,编程实现

import java.util.Scanner;

public class Test {

public static void main(String[] args) {
int[] array = new int[1000];
for (int i = 0; i < 1000; i++) {
array[i] = i;
}
boolean loopFlag = true;

while(loopFlag) {
System.out.println("请输入字符:");
Scanner sc = new Scanner(System.in);
String result = sc.nextLine();
if ("A".equalsIgnoreCase(result)) {
array = sort(array, result);
print(array);
} else if ("B".equalsIgnoreCase(result)) {
array = sort(array, result);
print(array);
} else if ("C".equalsIgnoreCase(result)) {
array = sort(array, result);
print(array);
} else {
System.out.println("你输入的不合法,请重新输入...");
}
System.out.println("按Y/y继续,按N/n退出?");
Scanner scanner = new Scanner(System.in);
String input = scanner.nextLine();
if ("N".equalsIgnoreCase(input)) {
loopFlag = false;
System.out.println("退出成功!");
}
}
}

/**
* @param a
* @param b
* @param type 比较类型
* @return 若a>b 返回true
*/
public static boolean compare(int a, int b, String type) {
int hundredsDigitA = a / 100;
int tenDigitA = a % 100 / 10;
int singleDigitA = a % 100 % 10;

int hundredsDigitB = b / 100;
int tenDigitB = b % 100 / 10;
int singleDigitB = b % 100 % 10;

if("B".equalsIgnoreCase(type)) {
// 十位>个位>百位
if (tenDigitA > tenDigitB) {
return true;
} else if(tenDigitA < tenDigitB){
return false;
} else {
if (singleDigitA > singleDigitB) {
return true;
} else if(singleDigitA < singleDigitB){
return false;
} else {
if (hundredsDigitA > hundredsDigitB) {
return true;
} else if(hundredsDigitA < hundredsDigitB){
return false;
} else {
// a,b相等,返回true/false都可以,基本上不会走到这一步
return true;
}
}
}
} else if ("C".equalsIgnoreCase(type)) {
// 个位>百位>十位
if (singleDigitA > singleDigitB) {
return true;
} else if(singleDigitA < singleDigitB){
return false;
} else {
if (hundredsDigitA > hundredsDigitB) {
return true;
} else if(hundredsDigitA < hundredsDigitB){
return false;
} else {
if (tenDigitA > tenDigitB) {
return true;
} else if(tenDigitA < tenDigitB){
return false;
} else {
// 相等,返回true/false都可以,基本上不会走到这一步
return true;
}
}
}
} else {
// 百位>十位>个位
if (hundredsDigitA > hundredsDigitB) {
return true;
} else if(hundredsDigitA < hundredsDigitB){
return false;
} else {
if (tenDigitA > tenDigitB) {
return true;
} else if(tenDigitA < tenDigitB){
return false;
} else {
if (singleDigitA > singleDigitB) {
return true;
} else if(singleDigitA < singleDigitB){
return false;
} else {
// 相等,返回true/false都可以,基本上不会走到这一步
return true;
}
}
}
}
}

/**
*
* @param array 排序数组
* @param type 排序类型,传入字符串"A"、"B"、"C"
* @return
*/
public static int[] sort(int[] array, String type) {
int length = array.length;
for (int i = 0; i < length; i++) {
for (int j = 0; j < length - 1; j++) {
if (!compare(array[j], array[j+1], type)) {
// 如果前面的数小于后面的数,就换位
int temp;
temp = array[j];
array[j] = array[j+1];
array[j+1] = temp;
}
}
}
return array;
}
public static void print(int[] array) {
for (int number : array) {
System.out.print(number + ">");
}
System.out.println();
}
}
种,厚度~ cm,其作用是杀灭病菌增强抗性加速萌
温馨提示:答案为网友推荐,仅供参考
相似回答