Odd Tiger 360Java Pen question

Source: Internet
Author: User
Tags finally block gcd greatest common divisor

1 Questions
The output after executing the following program is ()
public class Test {
public static void Main (string[] args) {
StringBuffer a = new StringBuffer ("a");
StringBuffer B = new StringBuffer ("B");
Operator (A, b);
System.out.println (A + "," + B);
}
public static void operator (StringBuffer x, StringBuffer y) {
X.append (y); y = x;
}
}
Answer: Ab,b
Parsing: A, B is a reference to the object, to the heap memory, A, B, two references to X, Y, execute x.append (y), change the X reference to the heap memory of the storage content, to AB, y = x, to refer to Y, point to Reference x point to the storage area, not change the reference B, Points to the contents of the storage space. A word resolved: string is a value pass, StringBuffer is a reference pass. So that's it.
2 Questions
Some of the most scalable patterns in a structured pattern are ()
Answer: Decoration mode
Resolution: A Decorative Mode
Definition: Dynamically add some extra responsibilities to an object, just like painting on a wall. Using the decorator mode, it is more flexible to achieve the expansion of the function by the method of generating subclasses.
Design: Often can use inheritance to achieve the expansion of the function, if these need to expand the variety of functions, it is bound to generate a lot of subclasses, increase the complexity of the system, while the use of inheritance to achieve functional expansion, we must be able to foresee these expansion functions, these functions are compile-time determined, is static. The function of the decoration mode is to:
1. Extended function
2. No inheritance
In this case, it can be considered as "the best embodiment" of extensibility.
3 Questions
In Linux, the file.sh file is executed #chmod 645 file.sh, and the file's permissions are ()
Answer:-rw-r–r-x
Resolution: The number of permissions corresponding to Linux is:
R =4, W =2, x =1
So, 6 is rw-.
4 is r –.
5 is r-x.
So, choose D.
4 Questions
TCP to establish a connection process using three handshake, the third handshake message is known to send serial number 1000, confirm that the serial number is 2000, the second handshake message to send the serial number and confirm the serial number respectively for
Answer: 1999,1000
Parsing: The sending sequence is the serial number of its own delivery paper, the current send serial number is the last time the serial number +1
Confirm that the serial number is received from the other sender serial number +1
The third handshake sends a serial number of 1000, which indicates that the first handshake sent the serial number is 999, note: Here is the handshake
, therefore, the confirmation sequence number of the second handshake is 1000, that is to confirm that the serial number is received from the other sender serial number +1.
The third handshake sends a confirmation number of 2000, indicating that the second handshake is sent with a serial number of 1999.
So, choose B.


5 Questions
The following TCP connection establishment procedures are described correctly:
Answer: The server may still be in SYN_RCVD state when the client is in the established state
Analysis: This topic mainly examines the TCP three times handshake, four times the state change of the wave, looks at the picture, deepens the impression.
The three-time handshake is as follows:
6 Questions
The address that belongs to the network 112.10.200.0/21 is ()
Answer: 112.10.206.0
Resolution: The first 21 bits are the network address and the last 12 bits are the host address.
110 corresponds to the first 8 bits, 10 corresponds to the second 8 bit, so 200 corresponds to the 3rd 8 bit
Another 200 binary is represented as 1100 1000
There are already 16 bits in front, so 11001 is the network address. 000 is the host address so, the maximum address is
"110 (decimal)" "10 (decimal)" "11001 111" "11111111" is converted to decimal 110.10.207.255
Therefore, the address range of the network is
110.10.200.0~110.10.207.255
So a is the correct answer
7 Questions
The following Java program code, after executing the result is ()
Java.util.HashMap map=new Java.util.HashMap ();
Map.put ("name", null);
Map.put ("name", "Jack");
System.out.println (Map.size ());
Answer: 1
Parse: HashMap can insert null key or value, when inserted, check whether the same key already exists, if not, then insert directly, if present, replace the old value with the new value, in the subject, the first put statement will key/ Value is inserted HashMap, and the second put, because there is already an item with key name, so the old Vaue is replaced with the new value, so after two put, there is only one Key/value key value pair in HashMap. That is (Name,jack). So, size is 1.
8 Questions
The following Java program code, after executing the result is ()
public class Test {
public static void Main (string[] args) {
Object o = new Object () {
public boolean equals (Object obj) {
return true;
}
};
System.out.println (O.equals ("Fred"));
}
}
Answer: TRUE
Resolution: 1. An anonymous inner class was created, and the Equals method of object was overridden.
2. The Equals method is called through O, and the method returns True.
9 Questions
Code snippet:
BYTE B1=1,b2=2,b3,b6;
Final byte b4=4,b5=6;
B6=B4+B5;
B3= (B1+B2);
System.out.println (B3+B6);
The description of the above code snippet is correct ()
Answer: statement: B3=B1+B2 compilation error
Parsing: The data type of the expression is automatically lifted, about the type of the automatic promotion, note the following rules.
① all the values of the Byte,short,char type will be promoted to the int type;
② if one operand is long, the result is a long type;
③ if one of the operands is a float type, the result is a float type;
④ if one of the operands is double, the result is a double type;
A variable declared final is optimized by the JVM, and the 6th line equals B6 = 10
If anything is wrong, please correct me.
10 Questions
The following code runs the result ()
public class test{
public int Add (int a,int b) {
try {
return a+b;
}
catch (Exception e) {
SYSTEM.OUT.PRINTLN ("catch statement block");
}
finally{
SYSTEM.OUT.PRINTLN ("finally statement block");
}
return 0;
}
public static void Main (String argv[]) {
Test test =new test ();
System.out.println ("and is:" +test.add (9, 34));
}
}
Answer: Finally statement block, and yes: 43
Parse: The program first executes the code in the try block before return (including the expression operation in the return statement), executes the finally block, and finally executes the return in the try block; The return statement after the finally block is no longer executed because the program has already return in the try block.
11 Questions
The following scenarios do not necessarily occur when the TCP section RST is:
Answer: Server host crashes after restarting
Resolution: Four scenarios will send the RST package:
1. Port not open
2. Request Timeout
3. Early closure
4. Receive data on a closed socket
12 Questions
Existing A,B,C,D,E,F Six statements in a database but currently the database is uncoordinated and some statements must be removed to restore the database's coordination. Known: (1) If statement A is preserved, statements B and C must be preserved. (2) If you keep statement E, you must delete both statement D and statement c. (3) Statement F can be retained only if the statement e is reserved. (4) Statement A is an important information, can not delete the above items if true, then which of the following must be true?
Answer: Delete both statement E and statement F
Analysis: According to (4), a must have;
Again according to (1), b,c must have, at this time there must be ABC
According to (2), because there is C, so there must be no E
According to (3), because there is no e, so there must be no F
In summary, ABC must have, EF must not, D not sure
13 Questions
The following statements about static Factory and factory methods are incorrect: ()
Answer: Both meet the Open and closed principle: Static factory creates objects in the If Else mode and modifies the source code when the demand is increased
Resolution: Select D, open and close principle: Opening to the expansion, closed to the modification. Static factory add need is to modify the source code, the modification is not closed, does not conform to the opening and closing principle.
14 Questions
There is a circular queue represented by an array of q[1..m], where F is the position of the current team head element in the array, R is the last position of the tail element (clockwise), and if the queue is non-empty, the formula for calculating the number of elements in the queue should be ()
Answer: (m+r-f) mod m
Resolution: (1) when the tail is greater than the head length of the tail-head when the tail is smaller than the head such as the tail in position 2nd, while the head in position 4th. The length of the table is 4 1 2, and this length is total length-(tail-head) = total length-(tail-head) and (tail-head) < 0 so get total length + (tail-head).
So merge two expressions to get (total length + (tail-head))% total length,% to prevent (1) situation overflow.
1
5 S
3
15 Questions
The following procedure calculates the greatest common divisor between two non-negative numbers using the Euclidean method:
Long Long gcd (long long X,long long y) {
if (y==0)
return x;
else return gcd (y,x%y);
}
We assume that the largest number in X, Y is the length of n, the basic operation time Complexity is O (1), then the time complexity of the program is ()
Answer: O (LOGN)
Analytic: The quick idea is the elimination method, is not with the fixed several values computation, therefore is not O (1), certainly also does not have each number to traverse each time to determine, is not O (n) and O (n^2), then chooses A.
Of course, if interested, you can do an experiment: in 10000 or 22 to divide the method, the number of operations most of which two number?
6765 and 4181
If you reduce or enlarge the upper bounds, you will find that the number that appears is the number in the Fibonacci sequence, which are two adjacent items.
Since the Fibonacci sequence is two adjacent to the GCD, each mod is only equivalent to a A-B, degenerated into a more subtractive technique, rather than the MoD's acceleration effect.
The Fibonacci sequence has a general formula, and the value of the nth term is related to the N times of some two irrational numbers. So, it's logn.
(Of course this proves to be unscientific)
16 Questions
The function for calculating the nth term of the Fibonacci sequence is defined as follows:
int fib (int n) {
if (n==0)
return 1;
else if (n==1)
return 2;
Else
return fib (n-1) +fib (n-2);
}
If the function call expression fib (10) is executed, the number of times the function fib is invoked is:
Answer: 177
Resolution: F (Ten) =f (9) +f (8) +1
= 2f (8) +f (7) +2
=3f (7) +2f (6) +4
=5f (6) +3f (5) +7
...
=55f (1) +34f (0) +88
55+34+88=177
17 Questions
The adjacent matrices of Figure G are as follows: the number of vertices and the number of sides of G are:
0 1 1) 1 1
1 0 1) 0 0
1 1 0) 1 1
1 0 1) 0 1
1 0 1) 1 0
Answer: 5,8
Analysis: Stupid method: The graph according to the neighboring matrix draw out;
Simple method: Only calculate the number of 1 on the upper or lower triangle of the main diagonal. The matrix is 5*5, there are five vertices, and for the main diagonal symmetry, there is no direction graph, and the number of edges equals the number of non-0 elements in the upper/lower triangular matrix.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Odd Tiger 360Java Pen question

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.