MiniTest 230304

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Mini test Engineering Software 1

Questions:

1. Identify and fix errors in the following code:


public class Welcome {
public void Main(String[] args) (
System.out.println(‘Welcome to Java!)
)
}
2. (i) A comment that begins with // must end with
(a) // (b) the end of a line (c) */ (d) }

(ii) Are the following statements correct? If so, show the output.
System.out.println(“the output for 25/4 is “ + 25 / 4);
System.out.println(“the output for 25/4.0 is “ + 25 / 4.0);

3. Declare the following:


• An int variable with an initial value of 0
• A long variable with an initial value of 1000
• A float variable with an initial value of 3.7
• A double variable with an initial value of 33.42
• A char variable with an initial value of 7
• A Boolean variable with an initial value of true

4. (i) How would you write the following arithmetic expression in Java?
4 3 + d (2 + a )
− 9(a + bc) +
3(r + 34) a + bd

(ii) Can Java run on any machine? What is needed to run Java on a computer? What are the
input and output of a Java compiler?
5. Assume that int a = 1 and double d = 1.0, and that each expression is independent. What
are the results of the following expressions?
a) a = 46 / 9;
b) a = 46 % 9 + 4 * 4 – 2;
c) a = 45 + 43 % 5 * (23 * 3 % 2);
d) a = 45 + 45 * 50 % a--;
e) a = 45 + 1 +45 * 50 % (++a + 1);
f) d += 1.5 * 3 + (++d);
g) d -= 1.5 * 3 + d++;
h) a %= 3 / a + 3;

Page 1 of 2
Mini test Engineering Software 1

6. Show and explain the output of the following code:


int i = 0;
System.out.println(--i + i + i++);
System.out.println(i + ++i);

7. Which of these statements are true?


a) Any expression can be used as a statement
b) The expression x++ can be used as a statement
c) The statement x = x + 5 is also an expression
d) The statement x = y = x = 0 is illegal
e) All the operators of the same precedence are evaluated from left to right.

8. Identify and fix the errors in the following code:


public class Test {
public void main(string[] args) {
int i;
int k = 100.0;
int j = i + 1;
System.out.println(“j is “ + j + “ and k is “ + k);
}
}

9. (i) Write a program that displays the message “Welcome to Java!”.


(ii) When the “Welcome to Java!” program is run, the first statement to be executed is:
a) the constructor
b) System.out.println(“Welcome to Java!”);
c) new Welcome();
d) the main method

10. (i) The keyword(s) that every types method must have is:
a) void
b) return
c) break
d) public static void
(ii) If we have two integers to return from a method, we can use:
a) an object as a parameter
b) an object as a return value
c) two parameters
d) answer (a) or (b)

Page 2 of 2

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy