Question: Program name: checksum.java Reads 10 non-negative integers from standard input (stdin), with each integer value in the range of 0..2^8-1 (I.e., 0..255). Stores the 6th

  • Program name: checksum.java
  • Reads 10 non-negative integers from standard input (stdin), with each integer value in the range of 0..2^8-1 (I.e., 0..255).
  • Stores the 6th input integer into a variable called "checksum", and resets this input value to zero (0).
  • Stores the sum of the integers read from stdin into a variable called "sum".
  • Performs integer division on this sum using 2^8 as the divisor to yield both a quotient and a remainder. These values are then stored in the variables "quotient" and "remainder", respectively.
  • Adds the values of "quotient" and "remainder" together, and stores this value into the variable "sum".
  • Subtracts this new value of "sum" from 2^8-1, and stores the result in a variable called "complement".
  • Outputs the value of "checksum" and "complement" to standard output (System.out).
  • If the value of "checksum" and "complement" are not the same, outputs the string "Error Detected!" to standard error (stderr)

import java.util.Scanner; class checksum { public static void main(String args[]) { final int max_int = 255; // The maximum size for the input int count = 10; // The number of integers to read from stdin int sum = 0; // Note that the "sum" might exceed max_int int checksum = 0; // The value of the 6th input integer int quotient; // The result of evaluating the assignment: quotient = sum / (max_int + 1); int remainder; // The result of evaluating the assignment: remainder = sum % (max_int + 1 ); int complement; // The result of evaluationg the assignment: complement = max_int - sum; Scanner stdin = new Scanner(System.in); 
 System.out.printf("Stored Checksum: %d, Computed Checksum: %d ", checksum, complement); if (checksum != complement ) { System.err.printf("Error Detected! "); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!