Advertisement
BilakshanP

Untitled

Jan 21st, 2025
6
0
6 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.93 KB | None | 0 0
  1. # 01 Introduction
  2.  
  3. 1. Which of the below statements is true?
  4. - [ ] Java is a compiled language like C and C++.
  5. - [ ] Java is different from C++ as it is Object Oriented.
  6. - [x] Java is just like C++, but implemented in a different way to make it portable and universal.
  7. - [ ] Java programs can run on any machine without any specific software requirements.
  8.  
  9. 2. What is the difference between the file `MyProgram.java` and the file `MyProgram.class`?
  10. - [ ] A `.java` file is a much larger binary file and a `.class` file is a smaller compressed version.
  11. - [ ] The programmer writes the `.class` file first, and the `.java` file is generated automatically later.
  12. - [ ] A `.java` file contains code written in the Java language, and a `.class` file contains code written in the C++ language.
  13. - [ ] The `.class` file is for object-oriented programming and the `.java` file is for procedural programming.
  14. - [x] `MyProgram.java` is a source code file typed by the programmer, and `MyProgram.class` is a compiled executable class file that is run by the JVM.
  15.  
  16. 3. **\[CODING\]** Write a program to print “Hello CodeQuotient”.
  17. ```java
  18. class Main {
  19. public static void main(String[] args) {
  20. System.out.println("Hello CodeQuotient");
  21. }
  22. }
  23. ```
  24.  
  25.  
  26. # 02 Variables
  27.  
  28. 1. WHich of the following can be used in a Java program as valid identifiers?
  29. - [ ] `"hello"`
  30. - [x] `AnnualExpenses`
  31. - [x] `G4`
  32. - [ ] `first-code`
  33. - [ ] `1987year`
  34. - [x] `_average`
  35. - [x] `ABC`
  36. - [ ] `for`
  37.  
  38. 2. Following expression `(1.1 + 0.2 + 1.1 + 2.2)` should likely be equal to `4.6`, but in Java it does not. Why?
  39. - [ ] Those numbers are integers in Java, so the sum is 4.
  40. - [ ] Java is unable to perform a + expression involving so many numbers, so the code does not compile.
  41. - [x] Real numbers are represented as imprecise floating-point numbers in the computer, and the limited precision led to a roundoff error.
  42. - [ ] The programmer forgot to cast the expression to type double, so the result is inaccurate.
  43.  
  44. 3. What is the output produced from the following statements? (Treat tabs as aligning to every multiple of eight spaces.)
  45. - **\[Inputs\]:**
  46. 1. ```java
  47. System.out.println("name\tage\theight");
  48. System.out.println("Amit\t25\t59");
  49. System.out.println("Gopal\t32\t56");
  50. System.out.println("Arun\t35\t60");
  51. ```
  52. 2. ```java
  53. System.out.println("Naveen is 61");
  54. System.out.println("The empty string is.");
  55. ```
  56. 3. ```java
  57. System.out.println("a\tb\tc");
  58. System.out.println("C:\nin\the downward spiral");
  59. ```
  60. - **\[Outputs\]:**
  61. 1. ```text
  62. name age height
  63. Amit 25 59
  64. Gopal 32 56
  65. Arun 35 60
  66. ```
  67. 2. ```text
  68. Naveen is 61
  69. The empty string is.
  70. ```
  71. 3. ```text
  72. a b c
  73. C:
  74. in he downward spiral
  75. ```
  76.  
  77. 4. What is the output from the following Java program?
  78. - **\[Input\]:**
  79. ```java
  80. class Main {
  81. public static void main(String[] args) {
  82. System.out.println("Dear -Codequotient-,");
  83. System.out.println();
  84. System.out.println("\tYour courses are wonderful to me. Isn't it");
  85. System.out.println("\nSincerely,");
  86. System.out.println("Gopal & Amit");
  87. }
  88. }
  89. ```
  90. - **\[Output\]:**
  91. ```txt
  92. Dear -Codequotient-,
  93.  
  94. Your courses are wonderful to me. Isn't it
  95.  
  96. Sincerely,
  97. Gopal & Amit
  98. ```
  99.  
  100. 5. What will be the output of below program:
  101. - **\[Input\]:**
  102. ```java
  103. class Main {
  104. public static void main(String[] args) {
  105. System.out.println("Dear -Programmer-,");
  106. System.out.println("\nI am a computer software, \nwhich understands only binary language");
  107. System.out.println("So, kindly provide input in binary only.\n");
  108. System.out.println("\nSincerely");
  109. System.out.println("JVM");
  110. }
  111. }
  112. ```
  113. - **\[Output\]:**
  114. ```txt
  115. Dear -Programmer-,
  116.  
  117. I am a computer software,
  118. which understands only binary language
  119. So, kindly provide input in binary only.
  120.  
  121.  
  122. Sincerely
  123. JVM
  124. ```
  125.  
  126.  
  127. # 03 Operators
  128.  
  129. 1. Find out the value of the following expressions. Make sure to give a value of the appropriate type (such as including a `.0` at the end of a double).
  130. - `1 + 2 * 3 + 7 * 2 % 5` = `11`
  131. - `26 % 10 % 4 * 3` = `6`
  132. - `22 + 4 * 2` = `30`
  133. - `23 % 8 % 3` = `1`
  134. - `12 - 2 - 3` = `7`
  135. - `6 / 2 + 7 / 3` = `5`
  136. - `6 * 7 % 4` = `2`
  137. - `3 * 4 + 2 * 3` = `10`
  138. - `177 % 100 % 10 / 2` = `3`
  139. - `89 % (5 + 5) % 5` = `4`
  140.  
  141. 2. What will be the value of the following expressions. Make sure to give a value of the appropriate type (such as including a .0 at the end of a double).
  142. - `4.0 / 2 * 9 / 2` = `9.0`
  143. - `2.5 * 2 + 8 / 5.0 + 10 / 3` = `9.6`
  144. - `12 / 7 * 4.4 * 2 / 4` = `2.2`
  145. - `4 * 3 / 8 + 2.5 * 2` = `6.0`
  146. - `(5 * 7.0 / 2 - 2.5) / 5 * 2` = `6.0`
  147. - `41 % 7 * 3 / 5 + 5 / 2 * 2.5` = `8.0`
  148. - `10.0 / 2 / 4` = `1.25.`
  149. - `8 / 5 + 13 / 2 / 3.0` = `3.0`
  150. - `2 * 3 / 4 * 2 / 4.0 + 4.5 - 1` = `4.0`
  151. - `813 % 100 / 3 + 2.4` = `6.4`
  152.  
  153. 3. Suppose you have an `int` variable called `val1`. Use `/` (division) first and then use `%` (modulus) operator to solve following queries: (Don't use any parentheses or spaces), for example `val1/2;` **Note**: Don't forget to use a semicolon(;) after each statement.
  154. 1. `val1%10;`
  155. 2. `val1/10%10;`
  156. 3. `val1/100%10;`
  157.  
  158. 4. Given a variable called count which takes on the values 1, 2, 3, 4 and so on. You are going to formulate expressions in terms of count that will yield different sequences. Fill in the solution boxes below, indicating an expression that will generate each sequence. Your answers should be in the form `(±coefficient*count±constant)` in that order without any spaces, or the solution checking may not be accurate. For example for a sequence like `2, 4, 6, 8, 10, 12, ...` the expression will be `(2*count+0)`
  159. 1. `(15*count-11)`
  160. 2. `(-10*count+40)`
  161. 3. `(4*count-11)`
  162. 4. `(-3*count+100)`
  163.  
  164. 5. Given the following variable declarations:
  165. ```
  166. int a = 2;
  167. int b = -4;
  168. int c = 2;
  169. ```
  170. What are the results of the following relational expressions? Write (true/false).
  171. - `a == 2` = `true`
  172. - `a + b > 0` = `false`
  173. - `a - c != 0` = `false`
  174. - `a * b >= c` = `true`
  175. - `b / b == 1` = `true`
  176. - `b == c` = `false`
  177. - `a + b >= b + c` = `true`
  178.  
  179. 6. **\[CODING\]** Write a program to calculate the gross salary of an employee. Basic salary will be provided as input and HRA is 10% of basic salary and DA is 20% of the basic salary.
  180.  
  181. The formula for calculating the gross salary will be: `Gross Salary = Basic Salary + HRA + DA`
  182. Where `HRA = 10% of basic salary` and `DA = 20% of Basic Salary`
  183.  
  184. **\[Input Description\]:** Each test case will contains a single value n (basic salary) where `n >=100`.
  185.  
  186. **\[Output Description\]:** For each input case, calculate and print the gross salary.
  187.  
  188. **\[Sample Input\]:** `5000`
  189.  
  190. **\[Sample Output\]:** `6500`
  191.  
  192. ```java
  193. class Main {
  194. public static void main(String[] args) {
  195. System.out.println("Hello CodeQuotient");
  196. }
  197. }
  198. ```
  199.  
  200.  
  201. # 04 Conditional and Loops
  202. # 05 Arrays in Java
  203. # 06 Bitwise Operators
  204. # 07 OOPs Introduction
  205. # 08 Inheritance - 1
  206. # 09 Inheritance - 2
  207. # 10 Strings
  208. # 11 Exception Handling
  209. # 12 Threads & Wrappers
  210. # 13 Generics & Collections
  211. # 14 Files & Streams
  212.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement