Written test summary

Written test summary

1. Each test paper has an 8-digit binary serial number. It is valid if and only if a serial number contains an even number of ones. For example, 00000000 and 01010011 are all valid serial numbers, but 11111110 are not. So, there are () valid serial numbers. The
answer is actually this way, I didn’t expect it

Analysis: There are a total of 2^8=256 sequences, which either contain an even number of 1s or an odd number, so the half is divided into 128.

2. For six pens, the colors of the pen body and cap are the same: but the colors of the six pens are different. How many possibilities are there for all pen bodies to wear the wrong cap?
The first step is to put the n-th element in a position, such as position k, there are a total of n-1 methods; the
second step, to put the element numbered k, there are two situations at this time: ⑴ put it in the position n, then, for the remaining n-1 elements, since the kth element is placed at position n, there are D(n-2) methods for the remaining n-2 elements; ⑵the kth element does not take it Put it at position n. At this time, for these n-1 elements, there are D(n-1) methods (equivalent to a pair of K at the original N position. At that time, because K was not placed at the N position, it formed Similar to "Troubleshooting, cannot constitute a matching language", there are n-1 elements); in
summary,
D(n) = (n-1) [D(n-2) + D(n-1)]
Answer: 265

3. Find the result of code execution

public class StringTest1 {
    
    
    public static void modify(String value) {
    
    
        value.toUpperCase();
        value += "3.0";

        System.out.println(value);
    }

    public static void main(String[] args) {
    
    
        String value = new String("alibaba");
        StringTest1.modify(value);

        System.out.println(value);
    }
}

alibaba3.0
alibaba
analysis: toUpperCase() has a return value, it is useless to call it directly without assigning a value.

class StringTest{
    
    
    public static void modify(StringBuilder value) {
    
    
        value.append("3.0");

        System.out.println(value);
    }

    public static void main(String[] args) {
    
    
        StringBuilder value = new StringBuilder("alibaba");
        StringTest.modify(value);

        System.out.println(value);
    }
}

alibaba3.0
alibaba3.0

Guess you like

Origin blog.csdn.net/weixin_43337081/article/details/109096007