Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: sequence of integers

  1. #1
    Junior Member
    Join Date
    Feb 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post 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


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default 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.

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default 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

  4. #4
    Junior Member
    Join Date
    Feb 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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.

Similar Threads

  1. Returning the equilibrium index in a sequence of integers
    By thanasisk in forum Algorithms & Recursion
    Replies: 4
    Last Post: September 3rd, 2013, 02:20 PM
  2. BFS Travel not in the sequence
    By keat84 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: February 8th, 2012, 09:19 PM
  3. [SOLVED] Writing Integers to .txt File; Returning Random Characters Instead of Integers
    By verbicidalmaniac in forum File I/O & Other I/O Streams
    Replies: 2
    Last Post: March 8th, 2011, 09:42 PM
  4. Determine the two smallest integers from a set of user input integers
    By bpontin in forum Loops & Control Statements
    Replies: 4
    Last Post: October 17th, 2010, 06:38 PM