Java Interview questions Summary

Source: Internet
Author: User
Tags class definition string format

A few days ago in the Java interview problems encountered, this is only part of the problem, there are many questions in the interview about data structures and algorithms. Here to summarize, hope that the ability of people can try to do, and in the comment area to leave your answer, let everyone learn from each other. Thanks

Programming section

Question 1th *

The known classes are defined as follows

class Node {

public Doublevalue;

public list<node>children;

    }

Change the following recursive program to a non-recursive program (the output of two programs should be consistent in sequence)

public staticvoid Process (node node) {

for (int i = 0; i < node. Children . Size (); i++) {

Node Child = node. Children . Get (i);

if (child. value < node. value ) {

Process(child);

            }

        }

System. out . println (node. value );

for (int i = 0; i < node. Children . Size (); i++) {

Node Child = node. Children . Get (i);

if (child. value >= node. value ) {

Process(child);

            }

        }

    }

Question 2nd *

Please complete the following procedures, input as a character array (each character in the array is not the same) and the number of N, the return value is composed of these characters of all the length of the string n

For example, the input is {' A ', ' B ', ' C '} and the number 1, then the return value is {"A", "B", "C"}

For example, enter {' A ', ' B ', ' C ', ' d '} and number 2, the return value is {"AB", "AC", "ad", "Ba", "BC", "BD", "CA", "CB", "CD", "Da", "db", "DC"}

public string[] doit (char[]chars) {

        ......

    }

Question 3rd * *

Refer to the 1th node class definition, the node class defines a tree structure, please refine the following program

Enter node to meet the following criteria:

1 node value is a floating-point number greater than 0

2 The value of node's subordinate nodes (and the lower nodes) may be null or a floating-point number greater than 0

The function of the program is as follows:

1 set a floating-point number greater than 0 for all value in the tree structure that is null

2 Non-leaf nodes (i.e. nodes with a number greater than 0 children) equal to the sum of the value of its children

public void doit (nodenode) {

        ......

    }

Question 4th * * *

The saga language consists of variable definitions, variable assignments, and conditional execution of three statements, where the variable definition must precede the other two statements, and three statements are defined as follows:

A variable definition consists of a variable name and a constant value:

def variable name = constant value

A variable assignment consists of a variable name and an operation expression:

Variable name = op-expression

Conditional execution consists of a comparison expression and a series of variable assignments:

if (comparison expression) {

Variable Assignment value 1

Variable Assignment value 2

......

}

which

A) variable names are made up of lowercase letters

b) constant values are floating-point numbers, such as 1.1,2.0, etc.

c) The arithmetic expression consists of a variable, a constant value, an operator subtraction (+,-, *,/), and parentheses

c) The comparison expression consists of two op-expressions plus a comparer (>,< =), which is an example of a+b>100.0

Example of a Saga language program:

def a=100.0

def b=200.0

def c=1.0

def d=0.0

C= (A+B)/2.0

if (c=150.0) {

d=d+1.0

d=d+1.0

}

Please complete the following program (write ideas), input is any Saga language program (string format), the return value is the program all the variables and their final value.

publicmap<string, double> doit (Stringprog) {

        ......

    }

Data Analysis Section

Question 1th * *

is a column of time series variables, the green point is the normal data point, and the red is the anomaly data point. Please design the algorithm to identify the anomaly, and briefly describe the algorithm framework and content points.










Logical AND geometric parts

Question 1th * * *

20 ball, in order to mark the sequence number 1-20, the ball into a box, the teacher from the box to randomly remove 2 balls, the serial number is a and B, will A and B and tell the student a, the product of A and B tell the student B, and then

A Q B: Do you know how much A and B are?

B Answer: I don't know.

B Q: Do you know how much A and B are?

A answer: Do not know

B said: Oh, I know.

A said: Oh, I also know

Please answer the number A and B respectively, and write the reasoning process.

Question 2nd * *

The side length of the known parallelogram are a and b, the external square, only the outer contact, without the external edge, the range of the external square edge length C is obtained.



Java Interview questions Summary

Related Article

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.