The words you are searching are inside this book. To get more targeted content, please make full-text search by clicking here.
Discover the best professional documents and content resources in AnyFlip Document Base.
Search
Published by shariraliza, 2021-04-18 21:50:30

OT2_Q

OT2_Q

PROGRAMMING

Output Tracing_2

OT2

Question 1 3 marks
Write the output for the following programs.

Given the following declarations

int x = 0, y = 5, z = 5;

if ( y + z >10)
y = 99;
z = 8;
x=z;

System.out.print(x +"\t" +y +"\t"+z);

Question 2 3 marks
Study the program segment below and answer the
question that follow.

tempCelcius = sc.nextDouble( );

If (tempCelcius > 37)
System.out.println(“You may have a fever.”);
System.out.println(“Please seek help at the nearest clinic.”);

Provide the output for the following input.
i) 40
ii) 35
iii) 37

Question 3 3 marks
What are the values after the following program segment
is executed.

int code = sc.nextInt();

if (code==1)
System.out.print(“Pulau Kapas here I come”);

else if (code==2)
System.out.print(“Pulau Redang wait for me!”);

else
System.out.print(“Pulau Tioman is awesome!”);
System.out.print(“\nLets get loud!”);

Test the program using the following input:
i) 1 ii) 2 iii) 4

Question 4 1 mark
Assume that you have entered 79 as an input for mark. Trace the
correct output for this program segment.

class Mark{
public static void main(String [] args){
java.util.Scanner sc = java.util.Scanner(System.in);

double mark = sc.nextDouble();

if( marks >= 80)
System.out.print(“Excellent!”);
System.out.print(“\nBravo”);

}
}

Question 5 2 marks
Study the program segment below and answer the questions that
follow. Provide the output for the following input 39 and 73.

class LuckyNumber{
public static void main(String [] args){
java.util.Scanner sc = java.util.Scanner(System.in);

int number = sc.nextInt();
if( number >=50)

System.out.print(“This is the lucky number for today!”);
else

System.out.print(“You’re not so lucky!”);
System.out.print(“\nYee Haa..”);
}
}

Question 6 2 marks
Study the Java program below and what is the expected answers if
user enter 10 and 20.


Click to View FlipBook Version