meo786
Welcome to meo786
Please Log In and Enjoy with us. I hope you will find more "Fun With Mobile, Computer & Management"

Thanks.

Muhammad Afzal Meo
+092 333 497 62 77

Join the forum, it's quick and easy

meo786
Welcome to meo786
Please Log In and Enjoy with us. I hope you will find more "Fun With Mobile, Computer & Management"

Thanks.

Muhammad Afzal Meo
+092 333 497 62 77
meo786
Would you like to react to this message? Create an account in a few clicks or log in to continue.

IT430_JavaScripting (for MBA 3rd semester students)

Go down

IT430_JavaScripting (for MBA 3rd semester students) Empty IT430_JavaScripting (for MBA 3rd semester students)

Post by Admin Sat Sep 05, 2009 7:39 am

Questions

1. Operators may be used in building expressions, which compute values.
2. Expressions are the core components of statements.
3. Statements may be grouped into blocks.
4. The following code snippet is an example of a compound expression.

1 * 2 * 3

5. Statements are roughly equivalent to sentences in natural languages, but instead of ending with a period, a statement ends with a semicolon.
6. A block is a group of zero or more statements between balanced braces and can be used anywhere a single statement is allowed.

Ex:

Identify the following kinds of expression statements:

* aValue = 8933.234; // assignment statement
* aValue++; // increment statement
* System.out.println("Hello World!"); // method invocation statement
* Bicycle myBike = new Bicycle(); // object creation statement




Objective Questions



1. The _____ statement allows for any number of possible execution paths.

1.if

2.while

3.switch

4.none

2. Question: How do you write an infinite loop using the for statement?

Answer:

for ( ; ; ) {



}

3. Question: How do you write an infinite loop using the while statement?

Answer:

while (true) {



}

Subjective Questions

1. Consider the following code snippet.

2. if (aNumber >= 0)

3. if (aNumber == 0) System.out.println("first string");

4. else System.out.println("second string");

5. System.out.println("third string");

a. Question: What output do you think the code will produce if aNumber is 3?

Solution:

second string

third string

b. Question: Write a test program containing the previous code snippet; make aNumber 3. What is the output of the program? Is it what you predicted? Explain why the output is what it is. In other words, what is the control flow for the code snippet?

Solution: NestedIf

second string

third string

3 is greater than or equal to 0, so execution progresses to the second if statement. The second if statement's test fails because 3 is not equal to 0. Thus, the else clause executes (since it's attached to the second if statement). Thus, second string is displayed. The final println is completely outside of any if statement, so it always gets executed, and thus third string is always displayed.

c. Question: Using only spaces and line breaks, reformat the code snippet to make the control flow easier to understand.

Solution:

if (aNumber >= 0)

if (aNumber == 0)

System.out.println("first string");

else

System.out.println("second string");



System.out.println("third string");

d. Question: Use braces { and } to further clarify the code and reduce the possibility of errors by future maintainers of the code.

Solution:

if (aNumber >= 0) {

if (aNumber == 0) {

System.out.println("first string");

} else {

System.out.println("second string");

}

}



System.out.println("third string");

Admin
Administrator

Number of posts : 8137
Age : 50
Location : Sharqi Abadi Mustafabad Kasur
Job/hobbies : Do more for other
Mode (i.e. cool, angry etc) : Serious
Warining :
IT430_JavaScripting (for MBA 3rd semester students) Left_bar_bleue0 / 1000 / 100IT430_JavaScripting (for MBA 3rd semester students) Right_bar_bleue

Rate by Admin :
IT430_JavaScripting (for MBA 3rd semester students) Left_bar_bleue0 / 1000 / 100IT430_JavaScripting (for MBA 3rd semester students) Right_bar_bleue

Reputation : 22
Registration date : 2007-10-23

https://meo786.forumotion.com

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum