Results 21 to 26 of 26
Thread: complete sequence
 12282010, 05:34 PM #21Senior Member
 Join Date
 Nov 2010
 Posts
 155
 Rep Power
 5
you mean what r the conditions that render a sequence incomplete...
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 [n1]; 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; 12282010 at 05:41 PM.
 12282010, 06:24 PM #22
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 13,951
 Blog Entries
 7
 Rep Power
 22
[QUOTE=aizen92;166331]you mean what r the conditions that render a sequence incomplete...
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+n1 for m <= 0?
kind regards,
JosI have the stamina of a seal; I lie on the beach instead of running on it.
 12282010, 10:22 PM #23Senior Member
 Join Date
 Nov 2010
 Posts
 155
 Rep Power
 5
I want to add something
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; }
 12292010, 07:12 AM #24Moderator
 Join Date
 Feb 2009
 Location
 New Zealand
 Posts
 4,703
 Rep Power
 13
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 [n1]; // etc as before }
Already the method is becoming quite long. You should think about using separate methods each doing just one thing.
 12292010, 08:37 AM #25Senior Member
 Join Date
 Nov 2010
 Posts
 155
 Rep Power
 5
Ok, it did the trick
thnx very much pbrockway2
 12292010, 12:58 PM #26Moderator
 Join Date
 Feb 2009
 Location
 New Zealand
 Posts
 4,703
 Rep Power
 13
Similar Threads

Fibonacci sequence
By ŖàΫ ỏƒ Ңόρę in forum New To JavaReplies: 6Last Post: 03252010, 07:59 AM 
Linked list sequence and array sequence
By Predz in forum New To JavaReplies: 1Last Post: 12312009, 02:30 AM 
calling sequence
By rocky in forum Web FrameworksReplies: 0Last Post: 04272009, 08:35 PM 
Fetching sequence
By Shivraj in forum New To JavaReplies: 1Last Post: 03192009, 03:30 PM 
Escape Sequence
By Punter in forum New To JavaReplies: 4Last Post: 02102009, 08:04 AM
Bookmarks