In: Computer Science
Trace the execution of the following program assuming the input stream contains the numbers 10, 3, and 14.3. Use a table that shows the value of each variable at each step. Also show the output (exactly as it would be printed)
// FILE: Trace.java // PURPOSE: An exercise in tracing a program and understanding // assignment statements and expressions. import java.util.Scanner; public class Trace { public static void main (String[] args) { int one, two, three; double what; Scanner scan = new Scanner(System.in); System.out.print ("Enter two integers: "); one = scan.nextInt(); two = scan.nextInt(); System.out.print("Enter a floating point number: "); what = scan.nextDouble() ; three = 4 * one + 5 * two; two = 2 * one; System.out.println ("one " + two + ":" + three); one = 46 / 5 * 2 + 19 % 4; three = one + two; what = (what + 2.5) / 2 ; System.out.println (what + " is what!"); } }
ANSWER:-
import java.util.Scanner;
public class Trace {
public static void main (String[] args)
{
int one, two, three; //
declaration of three integer variable
double what; // declaration
of one double variable
Scanner scan = new
Scanner(System.in); // scanner class use for user
input
System.out.print ("Enter two
integers: "); // message for user
one = scan.nextInt(); //
one take integer value by user example
one=10
two = scan.nextInt(); // two take integer value by user
example two=3
System.out.print("Enter a floating
point number: "); // message for user
what = scan.nextDouble() ;
// one take double value by user example
what=14.3
three = 4 * one + 5 * two;
// three=4*10+5*3=40+15=55
two = 2 * one; //
two=2*10=20
System.out.println ("one " + two +
":" + three); // output : one 20:55
one = 46 / 5 * 2 + 19 % 4;
// one = 9*2+3=18+3=21
three = one + two; // three
= 21+20=41
what = (what + 2.5) / 2 ; //
what=(14.3+2.5)/2=16.8/2=8.4
System.out.println (what + " is
what!"); // output : 8.4 is what!
}
}
OUTPUT:-
// If any doubt please comment