Java programming basic test question sharing
Single choice questions: (2 points for each question)
1. Which of the following statements is wrong? (B)
A. int i=10; B. float f=1.1; // float f=1.1f C. double d=34.4; D. byte b=127;
Long type data plus suffix L or l float type data plus suffix f or F integer defaults to int type floating point number defaults to double type
2. Which of the following is not a keyword in Java? (C)
A. public B. true C. main D. class
3. Which statement of the following program is correct
A. byte a=0,b=3; byte c =a+b;// The type of a + B is int B. short s = 23; s=s+12; // The bottom layer of S + 12 is converted to int for addition, so the result is int. C. short s=23; s+=12; // Equivalent to s = (short) (s + 12) d. float f = 23 + 23.23// The result of 23 + 23.23 is double
4. What are the results of the following procedures? (B)
A. 98 B. a1 C. 971 D. 197
//Before the empty string is placed, it is equivalent to string splicing. After the empty string is placed, 'a' + 1 ', the operation is performed first, and then spliced with the empty string. Byte, short and char can be automatically converted to int,
5. What are the results of the following procedures? (B)
A. 100 B. 101 C. 102 D. error reporting
6. The running result of the following program is (d)
A. A = 1 B. A = 3 C. compilation error D. normal operation but no output
7. After the following procedures are run, the results are correct: (b)
A. a=2,b=3 B. a=1,b=3 C. a=1,b=2 D. c=2
8. Operation results of the following program (b)
A. 2 B. 4 C. 6 D. 8
9. The following array definition error is (c)
A. int [] arr ={23,45,65,78,89}; // Static initialization B. int [] arr = New Int [10]// Dynamic initialization C. int [] arr = New Int [4] {3,4,5,6}; D. int [] arr={‘a',23,6};
//'a' can be automatically converted to int,
10. What are the results of the following procedures? (D )
A. x=1 y=2 B. x=7 y=1 C. x=7 y=2 D. x=2 y=2
11. The following is not the basic data type (d)
A. Int B. double C. long D. int [] / / reference type
12. What are the results of the following procedures? ( C)
A. a B. b C. c D. d
13. What are the results of the following procedures? (D)
A. 3 B. 4 C. 5 D. 6
14. The results of the following procedures
How many times do you print "Java foundation class" on the screen? ( C )
A. 5 B. 6 C. 7 D. 8
15. Read the following code snippet:
The correct statement of the execution result is (c)
A. Compile time will produce errors B. compile time is correct, run time will produce errors C. output zero D. output null
16 . The same option as the following code is (b)
A. for (int x=1; x<=100;x++){ sum=sum+x;} B. for (int x =0; x<=100;x+=2){ sum=sum+x;} // Even sum C. for (int x = 1; x < = 100; X + = 2) {sum = sum + X;}// Odd sum D. all pairs above
17. The following code output is (d)
A. 55 B. 45 C. 35 D. 30
18. Give the following code snippets:
Will you print the string "how are you?" The range of X is (c)
A. x>0 B. x > -3 C. x <= -3 D. x <=0 & x >-3
19. The execution result of the following code is (a)
A. 43 B. 23 C. 77 D. 9
20 . The result of the following program execution is (a)
A. 11 B. 12 C. 20 D. 21
Multiple choice questions: (3 points for each question)
21. Which of the following are legal identifiers (b.c.d)
A. 2variable B. variable2 C. what$ D. _ 3_
//Cannot start with a number, cannot be a keyword in Java, and letters are case sensitive
22. Among the following methods, (B, c) can form an overload relationship with the method int max (int a, int b, double C)
A. double max(int a,double c) B. void max(int a,double c,int b) C. int max(double a,int b) D. int max(int x,int y,double z)
//In the same class, the method name is the same, and the parameter type or number is different, regardless of the return value type
23. The following statement is correct (a, C,)
A. Byte, char data type can be automatically converted to int, B. float data type can be automatically converted to long. C. In the Java language, the default decimal is double D. byte a = 23; byte b=12; The result of a + B is byte type / / int
24. The following description of the method is correct (a, d)
A. Methods encapsulate function code blocks. B. when a method has no return value, you don't need to write anything. C. for a method without a return value, you can't have a return statement. / / each sentence can be followed by a default return; You can also manually add D. the method can have no formal parameters
25. The following description of the cycle is correct (a, d)
A. While loop first judges the loop condition and then executes the loop operation. B. while will execute at least once. C. do while will judge the loop condition first and then execute the loop operation. D. do while will execute at least once and then judge the loop
Short answer questions: (5 points for each question)
26: what are JDK, JRE and JVM, what is their use, and what is the relationship between them?
JDK: Java program development environment, including JRE and java development tools. JRE: Java program running environment, including JVM and Java core class library JVM: ensure the cross platform of Java language
27: is array a basic type? What are the basic data type classifications in Java?
No, the basic data types are divided into 4 categories and 8 types; Integer type: byte short int long character type: char boolean type: Boolean floating point type: float double
28: what is the method? What are its operational characteristics?
Methods: code blocks that complete specific functions. Running characteristics: no call, no execution; Method calls without passing data types; Methods and methods are at the same level and cannot be nested; When the method is defined, the parameters are separated by commas; Method does not call and does not execute; If the method has an explicit return value, be sure to use return to bring back a value.
29: what is an array? According to what can we get the elements in the array?
An array is a container that stores the same data type and can store multiple elements; We can get the elements in the array according to the index of the array.
30: when to use variables, if statements, and loop statements? You can score if you say something reasonable.
When a value is not fixed and changes within a certain range, it needs to be defined as a variable. If statement is used when judgment is needed; When there is a lot of duplicate code, you need to use circular statements. Programming topics: (10 points for each topic) Note: format, naming norms, notes.
31: write a piece of code in the main method to output the 99 multiplication table on the console.
32: please write a method sum to calculate the sum of two numbers. It is called in the main method.
33: please write a method printarray to traverse the array. Call in main method
summary
The above is all about the basic Java programming test questions shared in this article. Interested friends can continue to refer to: summary of Java advanced interview questions, Java common data structure interview questions (with answers), questions and examples related to Java array query. If you have questions, you can leave a message at any time. Xiaobian will reply to you in time. I hope it will help you learn java! Thank you for reading.