Java Reference
In-Depth Information
g.
if
the
boolean
variable
codeOk
is
true
Output a message indicating that the secret code was transmitted
correctly.
else
Output an error message.
Following this algorithm, the definition of the method
compareCode
is
public static void
compareCode(
int
[] list)
{
//Step a: Declare the variables
int
length2;
int
digit;
boolean
codeOk;
codeOk =
true
;
//Step b
System.out.println("Enter the length of the copy of "
+ "the secret code \nand a copy of "
+ "the secret code: ");
length2 = console.nextInt();
//Step c
if
(list.length != length2)
//Step d
{
9
System.out.println("The original code and "
+ "its copy are not of "
+ "the same length.");
return
;
}
System.out.println("Code Digit
Code Digit "
+
"Copy");
//Step e
for
(
int
count = 0; count < list.length; count++)
//Step f
{
digit = console.nextInt();
//Step f(i)
System.out.printf("%5d %15d",
list[count], digit);
//Step f(ii)
if
(digit != list[count])
//Step f(iii)
{
System.out.println(" corresponding code "
+ "digits not the same");
codeOk =
false
;
}
Search WWH ::
Custom Search