0% found this document useful (0 votes)
181 views2 pages

MiniTest 230304

This document contains a mini test with 10 questions on Java programming concepts. The questions cover topics like identifying and fixing errors in code, comments, data types, arithmetic expressions, operators, methods, and keywords. The test aims to assess understanding of fundamental Java concepts through true/false statements and code examples.

Uploaded by

Osama Maher
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
181 views2 pages

MiniTest 230304

This document contains a mini test with 10 questions on Java programming concepts. The questions cover topics like identifying and fixing errors in code, comments, data types, arithmetic expressions, operators, methods, and keywords. The test aims to assess understanding of fundamental Java concepts through true/false statements and code examples.

Uploaded by

Osama Maher
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 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