Write the output of the following code snippits, given the following declaration
ID: 671217 • Letter: W
Question
Write the output of the following code snippits, given the following declarations. If the code is not valid, write "error" as the answer. What is the role of the main function in Java? What is the difference between a float and a double? Write an if statement that checks to see if a number is between 5 and 10, inclusive? Assume that you have a class called House. What is the output of the following code? Assume that you have a text file called "myfile.txt". Write the code to open the file and append the line "This is the last line" to the file.Explanation / Answer
1.x/y=0 . (x/y=0.5, since x and y are integers,the value cannot be a decimal so the value is 0).
2.x*x/y = 5 (precedence)
3.x/z=0.5 (since z is double implicit type conversion happens)
4.a[1]*a[2]*x=60
5.a[5] is a garabage value or unknown memory address (array has indices only till 4)
6.x/2%10= 5
7.java.lang.NumberFormatException:
8.A simple stringA simple string
9.error: bad operand types for binary operator '*'
10. My number is 0.45
Short Answer:
1.The main method in the Java language is similar to the main function in C and C++. When the Java interpreter executes an application (by being invoked upon the application's controlling class), it starts by calling the class's main method. The main method then calls all the other methods required to run your application.
2.A float is a 32 bit IEEE 754 floating point, A double is a 64 bit IEEE 754 floating point.
3.if(num<5 && num >10)
4.My house has 100 square feet
5.PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("myfile.txt", true)));
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.