You are on page 1of 3

Mid-Term Test on Java Programming (1 / 3)

*** Write all answers directly on the test page. Use the back of the page if needed. ***
(1) Explain the difference between int and double.

(2) Explain what the term robust means, and outline why it is important for some software
to be robust, while it is not so important for other software.

(3) Explain the purpose of the return command in a method.

(4) The following method should print the numbers : 1 , 3 , 5 , 7 , 9 , ... , 99


Fill in the blanks to make it work correctly.

public void counting()


{
for ( ____ c = ___ ; _________ ; c = ________ )
{
System.out.println( c ) ;
}
}

(5) Study the following method:

public int getAge()


{
int age = 0;
while (age < 10 || age > 20 )
{ age = inputInt("Type your age:"); }
return age;
}

(a) Circle the numbers below that will be accepted and returned by this method:
0 15 12.5 30 20 -5

(b) Write a similar method that would input an amount of money, and would
only accept amounts between 10.00 and 100.00, including 10.00 and 100.00
Write your answer on the back of this page.
Mid-Term Test on Java Programming (2 / 3)

(6) State what the following commands will print:

int x = 30;
int y = 20;
int m = x / y;
Write your answers here
System.out.println("x" + "y");

System.out.println(x + y);

System.out.println( m );

if ( (m < x) && (m > y) )


{ System.out.println("okay"); }
else
{ System.out.println("bad"); }

if ( (x > 10) || (x < 5) )


{ System.out.println("yes"); }
else
{ System.out.println("no"); }

while ( x > y )
{
System.out.println( y ) ;
y = y + 1;
}

(8) A user must choose a new password. The password is only accepted if it follows these rules:
(a) It must have at least 6 letters.
(b) The maximum length is 10 letters.
(c) The first letter and the last letter must be different from each other.
(d) CAPITAL LETTERS are not permitted.
Here are some examples:
Accept : orange elephant xxxyyy
Reject : oregano exceptional xxxxxxxx Berlin

Write commands to input the password and print "accepted" or "rejected".


** Write your answer on the back of this page. **
Mid-Term Test on Java Programming (3 / 3)

(9) Decide whether each statement below is TRUE or false - circle your answer.

Java is case-sensitive. TRUE false

The following command is acceptable: TRUE false


int x = 12 / 7 ;

The command indexOf can be used to check whether a name contains the TRUE false
letter 'x' or not.

There is no difference between a String and a char. TRUE false

What is printed by the following commands? TRUE false


String test = "this is a test";
if (test.length()==14)
{ output("TRUE"); }
else
{ output("false"); }

EasyApp is the standard system for creating Java GUI applications. TRUE false

The purpose of substring is to search for whether a word is found in a TRUE false
sentence.

DeMorgan's Law says that the opposite of ( x < 50 && x > 10) is TRUE false
( x <50 || x >10).

You might also like