Java Reference
In-Depth Information
else
System.out.println();
}
if
(codeOk)
//Step g
System.out.println("Message transmitted OK.");
else
System.out.println("Error in transmission. "
+ "Retransmit!!");
}
The following is the algorithm for the method
main
.
1. Declare the variable to store the length of the secret code.
2. Prompt the user to enter the length of the secret code.
3. Get the length of the secret code.
4. Create the array to store the secret code.
5. Call the method
readCode
to read the secret code.
6. Call the method
compareCode
to compare the codes.
Main
Algorithm
PROGRAM LISTING
//*************************************************************
// Author: D. S. Malik
//
// Program: Code Detection
// This program checks whether the message received at the
// destination is error-free. If there is an error in the
// message, then the program outputs an error message and
// asks for retransmission.
//**************************************************************
import
java.util.*;
public class
CodeDetection
{
static
Scanner console =
new
Scanner(System.in);
public static void
main(String[] args)
{
int
codeLength;
//Step 1
System.out.print("Enter the length "
+ "of the code: ");
//Step 2
Search WWH ::
Custom Search