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

The solution to a java programming exercise where the goal is to trace the given code step by step and print the output. The code involves variable declarations, assignments, arithmetic operations, and string concatenation. The exercise requires showing all the work and the final output in an output window.

Typology: Exams

Pre 2010

Uploaded on 08/16/2009

koofers-user-yi2
koofers-user-yi2 🇺🇸

10 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

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