Consider the following code snippet. {:[" if (aNumber ">=0)xi],[" if (anumber "==0" ) "{]:} system.out.println ("first string") ; else {system.out.println ("sécond string"); 3system.out.println("third string") ; i. What output do you think the code will produce if "aNumber" is 3? [2 marks] ii. Write a test program containing the previous code snippet; make "aNumber" 3. What is the output of the program? Explain why the output is what it is i.e what is the control flow for the code snippet? [4 marks] iii. Using only braces, spaces and line breaks, reformat the oode snippet to make the control flow easier to understand. [3 marks] b) Consider the following class: iv. What are the class variables? [1 mark] Solve wh x=7
a) Consider the following code snippet. {:[" if (aNumber ">=0)xi],[" if (anumber "==0" ) "{]:} system.out.println ("first string") ; else {system.out.println ("sécond string"); 3system.out.println("third string") ; i. What output do you think the code will produce if "aNumber" is 3? [2 marks] ii. Write a test program containing the previous code snippet; make "aNumber" 3. What is the output of the program? Explain why the output is what it is i.e what is the control flow for the code snippet? [4 marks] iii. Using only braces, spaces and line breaks, reformat the oode snippet to make the control flow easier to understand. [3 marks] b) Consider the following class: iv. What are the class variables? [1 mark] Solve wh x=7
Step by step
Solved in 4 steps with 1 images