package com.wenj.test;
/**题目:
* 输入一串数,以','分隔,输出所有数中去掉最大值、最小值之后剩下的个数。(其中最大值与最小值可能有多个)
* Smple input:3,3,5,3,6,9,7,9 Sample outPut: 3
* @author wenj91-PC
* 分析: 先找出最大和最小值,然后直接统计不等于这两个数值的值个数
*/
public class TestGetNum {
public static void main(String args[]){
String strIn = "3,3,5,3,6,9,7,9";
TestGetNum tg = new TestGetNum();
System.out.println(tg.retTheLeftNum(strIn));
}
public int retTheLeftNum(String strIn){
String strTemp = strIn;
String[] strArr = strTemp.trim().split(",");
int[] numArr = new int[strArr.length];
for(int i=0; i<strArr.length; i++){
numArr[i] = Integer.parseInt(strArr[i]);
}
//找出最大最小值
int min = numArr[0];
int max = numArr[0];
for(int i=1; i<numArr.length; i++){
if(min>numArr[i]){
min = numArr[i];
}
if(max<numArr[i]){
max = numArr[i];
}
}
//计算除了最大与最小值的数
int count = 0;
for(int i=0; i<numArr.length; i++){
if(numArr[i] != min && numArr[i] != max){
count++;
}
}
return count;
}
}
/**题目:
* 输入一串数,以','分隔,输出所有数中去掉最大值、最小值之后剩下的个数。(其中最大值与最小值可能有多个)
* Smple input:3,3,5,3,6,9,7,9 Sample outPut: 3
* @author wenj91-PC
* 分析: 先找出最大和最小值,然后直接统计不等于这两个数值的值个数
*/
public class TestGetNum {
public static void main(String args[]){
String strIn = "3,3,5,3,6,9,7,9";
TestGetNum tg = new TestGetNum();
System.out.println(tg.retTheLeftNum(strIn));
}
public int retTheLeftNum(String strIn){
String strTemp = strIn;
String[] strArr = strTemp.trim().split(",");
int[] numArr = new int[strArr.length];
for(int i=0; i<strArr.length; i++){
numArr[i] = Integer.parseInt(strArr[i]);
}
//找出最大最小值
int min = numArr[0];
int max = numArr[0];
for(int i=1; i<numArr.length; i++){
if(min>numArr[i]){
min = numArr[i];
}
if(max<numArr[i]){
max = numArr[i];
}
}
//计算除了最大与最小值的数
int count = 0;
for(int i=0; i<numArr.length; i++){
if(numArr[i] != min && numArr[i] != max){
count++;
}
}
return count;
}
}