The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
September 2000

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

break statements

Posted by David Lowe on September 28, 2000 at 10:53 PM

If I wanted to place break statements instead of the found variable in the following code, where in the code do I place it and what do I type and what do I delete to make this program work. The output right now is dots going through the screen and then it says Done verification. The output should still be the same but with break statements in the code. Thanks.
public class BreakIt

public class BreakIt
{
public static void main(String [] args)
{
// loop and verify that the values are the same

for (int n = 0; n < 2000; n++)
{
if (f(n) != g(n) )
{
System.out.println("Values differ at index: " + n);
}
if (n % 100 == 0)
{
System.out.print("."); // progress dot
}
}

System.out.println("Done Verification.");
}

/* Some strange method */
static int f(int i)
{
int result = i;
boolean found = false;

for (int j = 3; !found && j < 1000; j = j + 3)
{

for (int k = 5; !found && k < 1000; k = k + 5)
{
if (j * k == i)
{
result = k;
found = true;
}
}

if (i == j)
{
found = true;
}
}

if (i % 3 == result)
{
result++;
}
else
{
result += 5;
}
return result;
}

static int g(int i)
{
int result = i;
boolean found = false;

for (int j = 3; !found && j < 1000; j = j + 3)
{

for (int k = 5; !found && k < 1000; k = k + 5)
{
if (j * k == i)
{
result = k;
found = true;
}
}

if (i == j)
{
found = true;
}
}

if (i % 3 == result)
{
result++;
}
else
{
result += 5;
}
return result;
}

}





Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us