Shang Xuetang Hundred Battles Programmer---Chapter 3 Interview Questions

1.3 What are the control statements?
Sequence structure, selection structure, loop structure
2. If {} is not written after the if statement, is the control scope of the if limited to the first sentence?
correct
3. What does Math.random() mean? What if you want to get a random number between 15-20?
Generate a random number between 0-1, including 0 but not 1
(int)(Math.random()*6)+15;
4. Can the functionality of the switch statement be completely replaced by the if else if else multiple choice structure? If so, why is the switch structure needed?
Can
switch is generally used to make multi-value judgments. If the judgment condition is an interval, it is best to use multiple if to do it. If it is equivalent, it is best to use switch to do it.
5. What type does the result of the expression in switch need to be?
byte,char,short,int
jdk1.5 added enumeration
jdk1.7 added String
6. In a switch statement, after a case starts executing, when does the execution of the case statement end?
Encounter break to end the execution of this case statement
7. In the switch statement, must default be written?
It is not necessary to write, when all conditions are not met, go to default, break to stop the current loop
8. What logic does the loop structure simulate in the real world?
The loop structure simulates the logic of a real-world 'repeated problem'
9. What is the difference between while and dowhile?
do-while executes at least once when the condition does not hold
10. Under what circumstances will there be an infinite loop? And write an example to
When the loop condition is always true, an infinite loop occurs
while(true){
System.out.println(“helloworld”);
}
11. Under what circumstances, there will be an infinite loop, and write an example
when the condition is permanent
12. What is the role of break and continue?
break loop terminates
counttnue terminates the loop, but still loops
13. In java. Is the passing of parameters by value or by reference?
pass by reference
14. What is the difference between method definition, formal parameters and actual parameters? describe in your own words
(formal parameter is type abstraction; actual parameter is formal parameter concrete assignment)
15. In the method definition, use actual parameters or formal parameters?
(formal parameter)
16. Is it necessary to write the variable type to define formal parameters?
(required; the type determines the memory, Java is the memory)
17. Does the actual parameter type have to match the formal parameter type?
(Because of that, is there a mismatch?)
18. What is method overloading? what's the effect?
(The method with the same name but only the parameters are different; yes, the input value is optional and flexible; for example, the cashier: you can give cash, and you can swipe the card if you have an amount)
19. What does the " two the same " and " 3 different" mean? Does different return value constitute overloading? Is the parameter name different enough to overload?
( 2 is the same: the parent and child class names are the same; the return value type is the same; 3 is different: parameter list, method body,)
20. In recursive algorithms, what do recursive head and recursive tail refer to?
(recursive method, recursive collapsing condition)
21. What are the advantages of recursive algorithms? weakness is?
(simple logic;; memory consumption; inefficient; slow)

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325904183&siteId=291194637