This is the 21st day of my participation in the August More Text Challenge
Difficulty level: Easy
The program
Program a
1) What is the output of the following program?
public class Test
{
private static float temp(a)
{
public static float sum = 21;
return(--(sum));
}
public static void main(String[] args)
{
Test test = newTest(); System.out.println(test.temp()); }}Copy the code
A) 21 B) 20 C) compilation error D) runtime error
Click here to jump to the answer
Program 2
2) What is the output of the following program?
public class Test
{
public static void main(String[] args)
{
int value = 3, sum = 6 + -- value;
intdata = --value + ++value / sum++ * value++ + ++sum % value--; System.out.println(data); }}Copy the code
a) 1
b) 2
c) 0
d) 3
Click here to jump to the answer
Application of three
3) What is the output of the following program?
public class Test
{
public static void main(String[] args)
{
int temp = 40;
if(temp == 30 && temp/0= =4)
{
System.out.println(1);
}
else
{
System.out.println(2); }}}Copy the code
A) 1 b) 2 c). Java lang. ArithmeticException runtime exception d) compile errors due to be divided exactly by 0
Click here to jump to the answer
Application of four
4) What is the output of the following program?
public class Test
{
public static void main(String[] args)
{
int temp = 9;
int data = 8; System.out.println(temp & data); }}Copy the code
a) 9
b) 8
c) 1000
d) 1001
Click here to jump to the answer
Application of five
5) What is the output of the following program?
public class Test
{
public static void main(String[] args)
{
int temp = null;
Integer data = null;
System.out.println(temp + ""+ data); }}Copy the code
A) null NULL B) compile error due to temperature C) compile error due to data d) runtime error
Click here to jump to the answer
The second part is the output and analysis of the program
Output and parsing
Program one output
The answer:
(c)Copy the code
Description:
Static variables are associated with classes and are therefore not allowed in the body of a method.
Program two output
The answer:
(b)Copy the code
Description:
Refer to the operator precedence rules in Java.
Program three output
The answer:
(b)
Copy the code
Description:
The && operator evaluates from left to right. If the first expression of the && operator evaluates to false, the second operator is not evaluated. There is no compilation error because dividing by 0 is a runtime exception.
Procedure 4 Answer
Answer:
(b)
Copy the code
Description:
The & operator is the logical bitwise sum operator in Java. The sum of 9(1001) and 8(1000) is 1000, which is 8.
Procedure 5 Answer
Answer:
(b)
Copy the code
Description:
Temp is a primitive data type. Null values cannot be assigned to raw data types. Data is an instance of the Integer class, so null values can be held.
That’s all for this article
Related articles:
Java program Java exercises 】 【 | at the output of the first set of (analysis) the output of the Java program Java exercises 】 【 | second (analysis) the output of a Java program | Java exercises 】 【 a third (including parsing) [Java exercises] | at the output of the Java program Fourth set (including the parse) the output of a Java program | Java exercises 】 【 5 sets (including parsing) the output of the Java program Java exercises 】 【 | 6 sets (including parsing) the output of a Java program | Java exercises 】 【 7 sets (including parsing) Java Java exercises 】 【 Program’s output | 8 sets (including parsing) the output of a Java program | Java exercises 】 【 9 sets of (including the parse) the output of a Java program | Java exercises 】 【 10 sets (recycling) the output of a Java program | Java exercises 】 【 11 sets of (including parsing) The output of a Java program | Java exercises 】 【 12 sets (including parsing) the output of a Java program | Java exercises 】 【 13 sets (set) the output of a Java program | Java exercises 】 【 14 sets (constructor) [Java exercises] | at the output of the Java program 15 sets of (internal) the output of a Java program | Java exercises 】 【 16 sets (thread)
I’ve been writing tech blogs for a long time and this is one of my tech posts/tutorials. Hope you like it! Here is a summary of all my original and works of source: GitHub, and this is my recently just built blog: Haiyong. Site, there is no content, put some HTML games, interested can try, source code can be their own F12 copy, or directly find me to.
If you really learn something new from this article, like it, bookmark it and share it with your friends. 🤗 and finally, don’t forget ❤ or 📑.