Docsity

CIS 120: PracticeTrace1 Program Trace Exercise Solution, Exams of Computer Science

Toggle sidebar
bg1
CIS 120: PROGRAM TRACE EXERCISE
PracticeTrace1: Trace the following program. Show in the OUTPUT WINDOW exactly
what is printed. SHOW ALL YOUR WORK!!
import javax.swing.*;
public class PracticeTrace1 {
public static void main (String[] args) {
// a1 a2 a3 f4 f5
int a1 = 12; // ____ ____ ____ ____ ____
int a2; // ____ ____ ____ ____ ____
int a3; // ____ ____ ____ ____ ____
float f4; // ____ ____ ____ ____ ____
float f5; // ____ ____ ____ ____ ____
a2 = 2; // ____ ____ ____ ____ ____
a3 = a1 / 3; // ____ ____ ____ ____ ____
f4 = 2.5f; // ____ ____ ____ ____ ____
f5 = (f4 + (float) a1) * 3.0f; // ____ ____ ____ ____ ____
a1 = a3 % 5; // ____ ____ ____ ____ ____
f4 = f4 / 4.0f; // ____ ____ ____ ____ ____
String out = “”;
out += a1 + " : " + a2 + " : " + a3 +”\n”;
out+= f4 + " : " + f5 + “\n”;
JOptionPane.showMessageDialog(null, out, “Test Trace”,
JOptionPane.INFORMATION_MESSAGE);
}//end main
}//end PracticeTrace1

Partial preview of the text

Download CIS 120: PracticeTrace1 Program Trace Exercise Solution and more Exams Computer Science in PDF only on Docsity!

CIS 120: PROGRAM TRACE EXERCISE

PracticeTrace1: Trace the following program. Show in the OUTPUT WINDOW exactly what is printed. SHOW ALL YOUR WORK!! import javax.swing.*; public class PracticeTrace1 { public static void main (String[] args) { // a1 a2 a3 f4 f int a1 = 12; // ____ ____ ____ ____ ____ int a2; // ____ ____ ____ ____ ____ int a3; // ____ ____ ____ ____ ____ float f4; // ____ ____ ____ ____ ____ float f5; // ____ ____ ____ ____ ____ a2 = 2; // ____ ____ ____ ____ ____ a3 = a1 / 3; // ____ ____ ____ ____ ____ f4 = 2.5f; // ____ ____ ____ ____ ____ f5 = (f4 + (float) a1) * 3.0f; // ____ ____ ____ ____ ____ a1 = a3 % 5; // ____ ____ ____ ____ ____ f4 = f4 / 4.0f; // ____ ____ ____ ____ ____ String out = “”; out += a1 + " : " + a2 + " : " + a3 +”\n”; out+= f4 + " : " + f5 + “\n”; JOptionPane.showMessageDialog(null, out, “Test Trace”, JOptionPane.INFORMATION_MESSAGE); }//end main }//end PracticeTrace