当前位置:网站首页>Some interview questions collected
Some interview questions collected
2022-07-25 06:11:00 【Eyes of years】
Some interview questions collected
- Define containers to store student information
1) Find the oldest student in the class
2) Find the information of the youngest classmate
import TreeMapDemo.Student;
import Internal comparator _ External comparator .Emp;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.TreeMap;
public class Example01 {
public static void main(String[] args) {
ArrayList<Student> list=new ArrayList();
list.add(new Student(1001," Wang Xiaoer ",18," Zhang San "));
list.add(new Student(1002," Wang Xiaosan ",19," Zhang San "));
list.add(new Student(1003," Xiao Si Wang ",20," Zhang San "));
list.add(new Student(1004," Wang Xiaowu ",21," Zhang San "));
list.add(new Student(1005," Zhang San ",22," Zhang San "));
// Anonymous inner class Interface polymorphism
new Comparator<Student1>(){
@Override
public int compare(Student1 s1, Student1 s2) {
return s1.getAge()-s2.getAge();
}
};
System.out.println(list);
// Traverse
for(Student stu :list){
System.out.println(stu.getAge());
}
System.out.println(" The oldest student in the class is :"+list.get(list.size()-1));
System.out.println(" The youngest student in the class is :"+list.get(0));
}
}
- Simulated check-in : Required HashMap Realization , You can add number check , time control
1、 Prepare a blank notebook
2、 Start checking in
3、 Sign in end
4、 Get how many people have signed in
5、 Get all the lists
6、 Check whether the monitor is on the list
import TreeMapDemo.Student;
import java.util.*;
/** * Simulated check-in : Required ArrayList * 1、 Prepare a blank notebook * 2、 Start checking in * 3、 Sign in end * 4、 Get how many people have signed in * 5、 Get all the lists * 6、 Check whether the monitor is on the list * */
public class Example02 {
public static void main(String[] args) {
ArrayList<Student1> list=new ArrayList();
HashMap<Integer,Student1> hm=new HashMap();
// Check in Scanner simulation
Scanner sc=new Scanner(System.in);
System.out.println("------------------ Start checking in --------------");
//static long currentTimeMillis() Returns the current time in milliseconds . The returned data is a long integer
//Date(long date) Distribute Date Object and initialize it to represent the self standard base time ( be called “ An era ”) Specified number of milliseconds since , namely 1970 year 1 month 1 Japan 00:00:00 GMT.
/*boolean after(Date date) If this method is called Date Object returns after the specified date true, Otherwise return to false */
// System.out.println(System.currentTimeMillis());
Date end=new Date(System.currentTimeMillis()+120*1000);// Get the current time and the counted time 60 second
// Cycle sign in Conditions for ending : 1) Enough people 2) It's time
while(true){
System.out.println(" Please enter the registration number :");
int snum=sc.nextInt();
System.out.println(" Please enter the student's name :");
String name=sc.next();// Get the entered name
Student1 stu=new Student1(name,new Date());//new A store name and time Student class
// list.add(stu);
hm.put(snum,stu);
// Number judgment
if(hm.size()==5){
System.out.println(" Everyone has signed in ");
break;
}
// The time limit
if(new Date().after(end)){
System.out.println(" It's time , End sign in ");
break;
}
}
System.out.println(" Attendance "+hm.size());
System.out.println(" Check in list "+hm);
// Traverse map Assemble and judge whether monitor Zhang San is on the list
Set<Integer> set=hm.keySet();
// To obtain a set aggregate , Use enhancements foreach and Iterator
Iterator it=set.iterator();// Get one Iterator object
while(it.hasNext()){
if(hm.get(it.next()).getName().equals(" Zhang San ")){
System.out.println(" Monitor Zhang San is on the list !");
}
}
}
}
- character string 1234… Turn to one, two, three, four …
import java.util.HashMap;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
public class Example3 {
public static void main(String[] args) {
System.out.println(" Please enter the number you want to convert :");
Scanner sc=new Scanner(System.in);
changUper(sc.next());
}
public static void changUper(String str){
HashMap<Character,String> hm=new HashMap<>();
hm.put('1'," one ");
hm.put('2'," Ii. ");
hm.put('3'," 3 ");
hm.put('4'," boss ");
hm.put('5'," wu ");
hm.put('6'," lu ");
hm.put('7'," Retailer, ");
hm.put('8'," ");
hm.put('9'," nine ");
hm.put('0'," zero ");
String str1="";
char[] chars=str.toCharArray();// Put the passed parameters str Convert to character array
Set<Character> set=hm.keySet();// Use HashMap Of keySet() Method
// Traverse
for(char ch:chars){
for (Character key:set){
if(key.equals(ch)){
// Put the traversal out key Value as parameter , Get the corresponding Value value , Then use string splicing
str1+=hm.get(key);
}
}
}
System.out.println(str1);
}
}
- One java The data is read from the file , Analyze the number of occurrences of each character , The results are stored in a file
file : zhoumolahahaha,lazijiliaojieyixia,daimadoubuhuijiubiewanyouxila
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashMap;
/** * One java The data is read from the file , Analyze the number of occurrences of each character , The results are stored in a file * file : zhoumolahahaha,lazijiliaojieyixia,daimadoubuhuijiubiewanyouxila * */
public class Example4 {
public static void main(String[] args) throws IOException {
recordCount();
}
public static void recordCount() throws IOException {
FileReader fr=new FileReader("D://count.txt");
FileWriter fw=new FileWriter("D://result.txt");
int count=0;
HashMap<Character,Integer> map=new HashMap<>();
// Traversing the read file
while((count= fr.read())!= -1){
//fr.read(), The number of characters read
char ch = (char)count;// Convert the received character wrapper class into characters
if(!map.containsKey(ch)){
// Determine whether the set contains the key of this character , Add... If not included
map.put(ch,1);
}else{
// If it is included, it covers ,value It's worth it 1
map.put(ch,map.get(ch) +1);
}
for(Character key : map.keySet()){
fw.write(key + "="+ map.get(key) +"\t");
};
}
fw.flush();
fw.close();
fr.close();
}
}
边栏推荐
- Equal proportion of R language test group: use the prop.test function to test whether the success proportion of the two groups is equal
- (15) [driver development] over written copy
- Context must be a dict rater solution
- context must be a dict rather解决
- R language uses rowmedians function to calculate the row data median value of all data rows in dataframe
- 剑指 Offer 36. 二叉搜索树与双向链表
- Binary search tree (day 75)
- Sword finger offer 36. binary search tree and bidirectional linked list
- Sword finger offer 54. the k-th node of the binary search tree
- (14)[驱动开发]配置环境 VS2019 + WDK10 写 xp驱动
猜你喜欢

SAP FICO section III BDC and ltmc import S4 financial account

【C语言】指针和数组的深入理解(第一期)

(2022年牛客多校一)I-Chiitoitsu(期望DP)

The computer accesses the Internet normally with the same network cable, and the mobile phone connects to WiFi successfully, but it cannot access the Internet

Pdf snapshot artifact

Tutorial: encryption keys in cloud (using golang and CLI)

(2022 Niuke multi School II) l-link with level editor I (dynamic planning)
![(14) [driver development] configuration environment vs2019 + wdk10 write XP driver](/img/90/0d94d26be8128d77de65919763fda5.png)
(14) [driver development] configuration environment vs2019 + wdk10 write XP driver

【每日一练】day(14)

Daily question brushing record (XXVIII)
随机推荐
MATLAB作图实例:5:双轴图
(16) [system call] track system call (3 rings)
Amazoncaptcha bypasses Amazon IP verification code with 95% success rate
VO, dto, do, Po distinction and use
剑指 Offer 54. 二叉搜索树的第k大节点
【每日一练】day(14)
ROI pooling and ROI align
动态规划学习笔记
R language obtains the data row where the nth maximum value of the specified data column is located in the data.table data
(Niuke multi School II) G-LINK with monotonic subsequence (construction question)
NFT: how to improve rentable NFT (erc-4907)
HTB-Arctic
Netease game Flink SQL platform practice
Common API of window
[Luogu p6629] string (runs) (tree array)
Equal proportion of R language test group: use the prop.test function to test whether the success proportion of the two groups is equal
Analyzing the principle of DNS resolution in kubernetes cluster
msys2常用配置
R language uses LM function to build multiple linear regression model and write regression equation according to model coefficient
(15)[驱动开发]过写拷贝