Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 01 Introduction
- 1. Which of the below statements is true?
- - [ ] Java is a compiled language like C and C++.
- - [ ] Java is different from C++ as it is Object Oriented.
- - [x] Java is just like C++, but implemented in a different way to make it portable and universal.
- - [ ] Java programs can run on any machine without any specific software requirements.
- 2. What is the difference between the file `MyProgram.java` and the file `MyProgram.class`?
- - [ ] A `.java` file is a much larger binary file and a `.class` file is a smaller compressed version.
- - [ ] The programmer writes the `.class` file first, and the `.java` file is generated automatically later.
- - [ ] A `.java` file contains code written in the Java language, and a `.class` file contains code written in the C++ language.
- - [ ] The `.class` file is for object-oriented programming and the `.java` file is for procedural programming.
- - [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.
- 3. **\[CODING\]** Write a program to print “Hello CodeQuotient”.
- ```java
- class Main {
- public static void main(String[] args) {
- System.out.println("Hello CodeQuotient");
- }
- }
- ```
- # 02 Variables
- 1. WHich of the following can be used in a Java program as valid identifiers?
- - [ ] `"hello"`
- - [x] `AnnualExpenses`
- - [x] `G4`
- - [ ] `first-code`
- - [ ] `1987year`
- - [x] `_average`
- - [x] `ABC`
- - [ ] `for`
- 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?
- - [ ] Those numbers are integers in Java, so the sum is 4.
- - [ ] Java is unable to perform a + expression involving so many numbers, so the code does not compile.
- - [x] Real numbers are represented as imprecise floating-point numbers in the computer, and the limited precision led to a roundoff error.
- - [ ] The programmer forgot to cast the expression to type double, so the result is inaccurate.
- 3. What is the output produced from the following statements? (Treat tabs as aligning to every multiple of eight spaces.)
- - **\[Inputs\]:**
- 1. ```java
- System.out.println("name\tage\theight");
- System.out.println("Amit\t25\t59");
- System.out.println("Gopal\t32\t56");
- System.out.println("Arun\t35\t60");
- ```
- 2. ```java
- System.out.println("Naveen is 61");
- System.out.println("The empty string is.");
- ```
- 3. ```java
- System.out.println("a\tb\tc");
- System.out.println("C:\nin\the downward spiral");
- ```
- - **\[Outputs\]:**
- 1. ```text
- name age height
- Amit 25 59
- Gopal 32 56
- Arun 35 60
- ```
- 2. ```text
- Naveen is 61
- The empty string is.
- ```
- 3. ```text
- a b c
- C:
- in he downward spiral
- ```
- 4. What is the output from the following Java program?
- - **\[Input\]:**
- ```java
- class Main {
- public static void main(String[] args) {
- System.out.println("Dear -Codequotient-,");
- System.out.println();
- System.out.println("\tYour courses are wonderful to me. Isn't it");
- System.out.println("\nSincerely,");
- System.out.println("Gopal & Amit");
- }
- }
- ```
- - **\[Output\]:**
- ```txt
- Dear -Codequotient-,
- Your courses are wonderful to me. Isn't it
- Sincerely,
- Gopal & Amit
- ```
- 5. What will be the output of below program:
- - **\[Input\]:**
- ```java
- class Main {
- public static void main(String[] args) {
- System.out.println("Dear -Programmer-,");
- System.out.println("\nI am a computer software, \nwhich understands only binary language");
- System.out.println("So, kindly provide input in binary only.\n");
- System.out.println("\nSincerely");
- System.out.println("JVM");
- }
- }
- ```
- - **\[Output\]:**
- ```txt
- Dear -Programmer-,
- I am a computer software,
- which understands only binary language
- So, kindly provide input in binary only.
- Sincerely
- JVM
- ```
- # 03 Operators
- 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).
- - `1 + 2 * 3 + 7 * 2 % 5` = `11`
- - `26 % 10 % 4 * 3` = `6`
- - `22 + 4 * 2` = `30`
- - `23 % 8 % 3` = `1`
- - `12 - 2 - 3` = `7`
- - `6 / 2 + 7 / 3` = `5`
- - `6 * 7 % 4` = `2`
- - `3 * 4 + 2 * 3` = `10`
- - `177 % 100 % 10 / 2` = `3`
- - `89 % (5 + 5) % 5` = `4`
- 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).
- - `4.0 / 2 * 9 / 2` = `9.0`
- - `2.5 * 2 + 8 / 5.0 + 10 / 3` = `9.6`
- - `12 / 7 * 4.4 * 2 / 4` = `2.2`
- - `4 * 3 / 8 + 2.5 * 2` = `6.0`
- - `(5 * 7.0 / 2 - 2.5) / 5 * 2` = `6.0`
- - `41 % 7 * 3 / 5 + 5 / 2 * 2.5` = `8.0`
- - `10.0 / 2 / 4` = `1.25.`
- - `8 / 5 + 13 / 2 / 3.0` = `3.0`
- - `2 * 3 / 4 * 2 / 4.0 + 4.5 - 1` = `4.0`
- - `813 % 100 / 3 + 2.4` = `6.4`
- 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.
- 1. `val1%10;`
- 2. `val1/10%10;`
- 3. `val1/100%10;`
- 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)`
- 1. `(15*count-11)`
- 2. `(-10*count+40)`
- 3. `(4*count-11)`
- 4. `(-3*count+100)`
- 5. Given the following variable declarations:
- ```
- int a = 2;
- int b = -4;
- int c = 2;
- ```
- What are the results of the following relational expressions? Write (true/false).
- - `a == 2` = `true`
- - `a + b > 0` = `false`
- - `a - c != 0` = `false`
- - `a * b >= c` = `true`
- - `b / b == 1` = `true`
- - `b == c` = `false`
- - `a + b >= b + c` = `true`
- 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.
- The formula for calculating the gross salary will be: `Gross Salary = Basic Salary + HRA + DA`
- Where `HRA = 10% of basic salary` and `DA = 20% of Basic Salary`
- **\[Input Description\]:** Each test case will contains a single value n (basic salary) where `n >=100`.
- **\[Output Description\]:** For each input case, calculate and print the gross salary.
- **\[Sample Input\]:** `5000`
- **\[Sample Output\]:** `6500`
- ```java
- class Main {
- public static void main(String[] args) {
- System.out.println("Hello CodeQuotient");
- }
- }
- ```
- # 04 Conditional and Loops
- # 05 Arrays in Java
- # 06 Bitwise Operators
- # 07 OOPs Introduction
- # 08 Inheritance - 1
- # 09 Inheritance - 2
- # 10 Strings
- # 11 Exception Handling
- # 12 Threads & Wrappers
- # 13 Generics & Collections
- # 14 Files & Streams
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement