Java定义一个11个元素的数组,从控制台输入一个数,若不存在则将此数替换数组中的最小值
1个回答
展开全部
不知道是不是符合你的要求
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class test48 {
public static void main(String[] args) throws NumberFormatException, IOException {
Integer []test={1,2,3,4,5,6,7,8,9,10,11};
List list = (Arrays.asList(test));
System.out.println(list);
Collections.sort(list);
System.out.println("输入你要查询的数");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int get = Integer.parseInt(br.readLine());
int t =Collections.binarySearch(list, get);
if(t<0){
list.set(0,get);
}
System.out.println("现在所存在的数"+list);
}
}
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class test48 {
public static void main(String[] args) throws NumberFormatException, IOException {
Integer []test={1,2,3,4,5,6,7,8,9,10,11};
List list = (Arrays.asList(test));
System.out.println(list);
Collections.sort(list);
System.out.println("输入你要查询的数");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int get = Integer.parseInt(br.readLine());
int t =Collections.binarySearch(list, get);
if(t<0){
list.set(0,get);
}
System.out.println("现在所存在的数"+list);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询