-
sequence of integers
I'm new in java so i really don't now what to do in this problem..my teacher wants me do a program for this problem ...anyone help me with this.
A sequence of integers is an "integer chain with rings of r" if the difference between each consecutive number is at most r.
Write a program that tests if a sequence of integers is an integer chain.
The program prompts the user to enter the number of integers (between 2 and 20) and the desired ring width 'r'.
It will output whether the sequence is a chain or where the chain is broken
Sample run 1:
Enter sequence length and ring width: 6 3
Enter 6 integers: 7 10 8 9 12 12
This is an integer chain of length 6 with rings of 3
-
Re: sequence of integers
Please read the forum rules. Double posting is one of them, and is not allowed. Your other post has been removed.
-
Re: sequence of integers
What problem(s) are you having with your code? Please post the code and your questions.
Be sure to wrap your code with[code=java]<YOUR CODE HERE>[/code] to get highlighting
-
Re: sequence of integers
[code =java]
package integersequence;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
public class IntegerSequence {
public static void main(String[] args) {
BufferedReader dataIn= new BufferedReader(new InputStreamReader (System.in));
String length = "";
System.out.println("Enter the Length:");
try{
length = dataIn.readLine();
} catch (IOException e){
System.out.print("Error");
}
System.out.println("The Length is:"+ length);
String ring = "";
System.out.println("Enter the Ring Width:");
try{
ring = dataIn.readLine();
} catch (IOException e){
System.out.print("Error");
}
System.out.println("The Ring Width is:"+ ring);
String sint = "";
System.out.println("Enter the integers:");
try{
sint = dataIn.readLine();
} catch (IOException e){
System.out.print("Error");
}
System.out.println("The Value of Integers are:"+ sint);
int x;
x= Integer.parseInt(length);
int[] anArray;
anArray = new int[x];
}
}
[/code]
i can't produce the answer
example answer on the output should be:
This is an integer chain of length 6 with rings of 3
or
Integer chain is broken at 6.
or
Sequence length is outside the requirements range.