1. Senior Member
Join Date
Nov 2010
Posts
155
Rep Power
8
you mean what r the conditions that render a sequence in-complete...
if so they are:

- there is a number greater than n - 1 // where n is the length of the sequence
- not all numbers between 1 and n - 1 are found as differences
- when there is a number between 1 and n - 1 that is repeated more than once

EDIT: Well i got it right finally

I added another for loop with an if statement in it that check the array diff in all of its elements if it has equal elements to return false

heres the code

Java Code:
```import java.util.*;
import java.io.*;

public class test
{
public static void main (String[] args) throws FileNotFoundException
{
Scanner input = new Scanner (new File(args[0]));
int n;
int end;
Boolean status = false;

while (input.hasNextLine())
{
n = input.nextInt();
end = n - 1;
int [] array = new int [n];
int [] diff = new int [n-1];

for ( int i = 0; i < n; i++)
{
array [i] = input.nextInt();
}

for ( int j = 0; j < n - 1; j++)
{
diff [j] = Math.abs(array[j] - array[j + 1]);
}

for ( int k = 0; k < n - 1; k++)
{
if ( diff [k] >= 1 && diff [k] <= end )
{
status = true;
}else{
status = false;
break;
}
}

if ( array.length == 1)
status = true;

[B]for ( int p = 0; p < n - 2; p++)
{
if ( diff [p] == diff [p + 1])
status = false;
}[/B]

if (status == true )
{
System.out.println("Complete Sequence");
}else{
System.out.println("Not Complete Sequence");
}
}
}
}```
Last edited by aizen92; 12-28-2010 at 04:41 PM.

2. [QUOTE=aizen92;166331]you mean what r the conditions that render a sequence in-complete...
if so they are:

- there is a number greater than n - 1 // where n is the length of the sequence
- not all numbers between 1 and n - 1 are found as differences
- when there is a number between 1 and n - 1 that is repeated more than once

Isn't that a complicated way of saying: a sequence of n numbers has to be the a permutations of the numbers m, m+1, m+2 ... m+n-1 for m <= 0?

kind regards,

Jos

3. Senior Member
Join Date
Nov 2010
Posts
155
Rep Power
8
I want to make sure that n is not greater than 3000

so i added this if statement after having n get the nextInt() the following statement

Java Code:
```if ( n >= 3000 )
{
System.out.println("Your sequence is greater than 3000 elements");
break;
}```
but the thing is after the break its finishing everything, i want it to continue for the next sequences, not to stop the whole program on this

4. Moderator
Join Date
Feb 2009
Location
New Zealand
Posts
4,717
Rep Power
16
You could try something like:

Java Code:
```while (input.hasNextLine())
{
n = input.nextInt();
if(n >= 3000)
{
System.out.println("Message");
input.nextLine(); // read the line and throw it away
continue;
}
end = n - 1;
int [] array = new int [n];
int [] diff = new int [n-1];

// etc as before
}```
-------------------------

Already the method is becoming quite long. You should think about using separate methods each doing just one thing.

5. Senior Member
Join Date
Nov 2010
Posts
155
Rep Power
8
Ok, it did the trick
thnx very much pbrockway2

6. Moderator
Join Date
Feb 2009
Location
New Zealand
Posts
4,717
Rep Power
16

Page 2 of 2 First 12

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•