import java.util.Scanner;public class TestStudent { public static void main(String[] args) { //从键盘获得数据 Scanner scan = new Scanner(System.in); //输入学生个数 System.out.println("请输入学生个数:"); int maxGrade=0; int count = scan.nextInt(); //确定成绩个数,并用数组保存 in
所谓的BitMap就是用一个bit位来标记某个元素所对应的value,而key即是该元素,由于BitMap使用了bit位来存储数据,因此可以大大节省存储空间. public class Test { //为了方便,假设数据是以数组的形式给我们的 public static Set<Integer> test(int[] arr) { //用来把重复的数返回,存在Set里,这样避免返回重复的数. Set<Integer> output = new HashSet<>();
题目 Being unique is so important to people on Mars that even their lottery is designed in a unique way. The rule of winning is simple: one bets on a number chosen from [1,104 ]. The first one who bets on a unique number wins. For example, if there ar
/** * 找出未出现的最小正整数 * @param A * @param n * @date 2016-10-7 * @author shaobn */ public static int findArrayMex(int[] a,int n){ int count = n; int temp = 0; int dir = 1; int num = 0; for(int i = 0;i<count-1;i++){ if(a[i]>a[i+1]){ temp = a[i]; a[i]= a[i
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><style type="text/css"&g
//通过Map 类实现,通过键值对的方式,可以将输入的字符串的每一个字符,作为键,每个字符出现的次数作为值:如下: public class Find { public static void main(String[] args){ String scan=new Scanner(System.in).nextLine();//获取键盘上输入的字符串: Map<Character,Integer> map = new HashMap<Character,Integer>();//
首先,要求找到最长最短字符串,我们应该用数组将其存起来,输入的个数是不固定的,我们就可以用Scanner获取要输入的个数,最终找到的个数也不固定,我们可以封装两个方法,并且返回值类型为数组. 我遇到的问题,开始我想到的是字符串拼接,么想到返回值用数组存,导致每次返回的个数都是固定的,就算有多个. 代码如下: import java.util.Scanner; //输入n行字符串,找出最长最短字符串(若有个数相同的,都打印出来) public class FindString { public s