Question

In: Computer Science

Trace the execution of the following program assuming the input stream contains the numbers 10, 3,...

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!"); } }

Solutions

Expert Solution

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


Related Solutions

Trace the execution of quicksort on the following array, assuming that the first item in each...
Trace the execution of quicksort on the following array, assuming that the first item in each subarray is the pivot value. Show the values of first and last for each recursive call and the array elements after returning from each call. Also, show the value of pivot during each call and the value returned through pivIndex. How many times is sort called, and how many times is partition called? 55 50 10 40 80 90 60 100 70 80 20...
4. Write a program trace for the pseudocode in Exercise • E4.6, assuming the input values...
4. Write a program trace for the pseudocode in Exercise • E4.6, assuming the input values are 4 7 –2 –5 0. Ans. first value minimum output • E4.6 --> This is the pseudocode Set a Boolean variable "first" to true. While another value has been read successfully If first is true Set the minimum to the value. Set first to false. Else if the value is less than the minimum Set the minimum to the value. Print the minimum.
Make a detailed trace of the execution of the following program fragment, giving the contents of...
Make a detailed trace of the execution of the following program fragment, giving the contents of all the registers, and memory locations involved. Assume that before execution begins the SS register contains 0410h, and the SP register 0100h, and that the contents of AX, BX, CX, and DX are 789Ah, 0020h, 2000h, and 1234h respectively. SS SP TOS AX BX CX DX Initial contents 0990 0100 / 789A 0020 2000 1234 after PUSH AX after PUSH BX after PUSH CX...
consider the following numbers: -5,-3,-1,1,3. assuming that these numbers are the sample data, use a pencil...
consider the following numbers: -5,-3,-1,1,3. assuming that these numbers are the sample data, use a pencil and calculator to calculate the mean, standard deviation and variance. please show work
Create a small program that contains the following. ask the user to input their name ask...
Create a small program that contains the following. ask the user to input their name ask the user to input three numbers check if their first number is between their second and third numbers
Input 10 integers and display the following: a. the sum of even numbers. b. the sum...
Input 10 integers and display the following: a. the sum of even numbers. b. the sum of odd numbers. c. the largest integer d. the smallest integer e. the total count of even numbers f. the total count of odd numbers. Using C++ program with for loop..
Task 3      Write a program that pushes the first 10 natural numbers to the stack,...
Task 3      Write a program that pushes the first 10 natural numbers to the stack, then pops those numbers. Use the debugger to view how the stack changes after each instruction. Once all the data has been pushed to the stack, take a screenshot of the stack in memory. Task 4     Write a subroutine called “Area” that calculates the area of a rectangle. Use accumulator A and B to pass the length and the width to the function....
Write the following program in MIPS: a) declare an array A of the following numbers: 3,...
Write the following program in MIPS: a) declare an array A of the following numbers: 3, 5, 8, 10, 12, 2, 76, 43, 90, 44 b) declare a variable called size which stores the number of element in array A, that is 10. c) write a subroutine to search for a number stored in an array and return true or false. In C++ the subroutine is as follows: search(array, size, number_To_Search) e.g. search(A, 10, 12) The subroutine should return 0...
Input from console 3 double numbers, compare these 3 numbers and display them from small to...
Input from console 3 double numbers, compare these 3 numbers and display them from small to great. In Java Please
in Java, write a program that takes an input of 4 numbers and splits them into...
in Java, write a program that takes an input of 4 numbers and splits them into 4 separate lines. EXAMPLE: so if input is 1994 the output should be 1 9 9 4
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT