Access Millions of academic & study documents

An arithmetic sequence is a sequence, in which the difference between

Content type
User Generated
Showing Page:
1/3
An arithmetic sequence is a sequence, in which the
difference between any two consecutive terms is the same,
i.e., the difference is a constant. For example, the
sequence that begins 1, 4, 7, 10, 13, 16, ... is an
arithmetic sequence since the difference between
consecutive terms is always 3. Write a Java program to
generate arithmetic sequences. Your program will invoke 2
methods: one method to generate the arithmetic sequence
and save it in a 1-dimensional array; and one method to
print that 1-dimensional array. Write your program so that
it will generate output similar to the sample output below:
How many times do you want to find arithmetic sequences?
-3 ERROR: Should be positive. REENTER: 3 What is the
first number in the sequence: 5 What is the difference
between consecutive terms: 3 How many numbers in the
sequence (up to 1000): 17 The arithmetic sequence is: 5 8
11 14 17 20 23 26 29 32 35 38 41 44 47 50 53 What is the
first number in the sequence: 1 What is the difference
between consecutive terms: 2 How many numbers in the
sequence (up to 1000) 25 The arithmetic sequence is: 1 3
5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43
45 47 49 What is the first number in the sequence: -15
What is the difference between consecutive terms: 5 How
many numbers in the sequence (up to 1000): 10 The
arithmetic sequence is: -15 -10 -5 0 5 10 15 20 25 30
SOLUTION: import java.util.Scanner; class
arithmeticSequence {public static final int SIZE = 1000;
public stativ void main (String[] args) {Scanner input = new
Scanner (System.in); int how_many, size; int first, diff;
System.out.print(\"How many times do you want to find
arithmetic sequences?\"); how_many =
input.nextInt();//COUNTINUE FROM HERE:

Sign up to view the full document!

lock_open Sign Up
Showing Page:
2/3
Solution
import java.util.Scanner;
class arthimeticSequence {
public static final int SIZE=100;
public static void main(String[] args){
Scanner input=new Scanner(System.in);
int how_many,size,first,diff;
while(1){
System.out.println(\"how many times you want
to find the arthimetic sequences ?\");
how_many=input.nextInt();
if(how_many < 1){
System.out.println(\"Error it must be
positive\");
continue;
}
for(int i=0;i<how_many;i++){
System.out.println(\"what is the first number in
the sequence\");
first=input.nextInt();
System.out.println(\"what is the difference between

Sign up to view the full document!

lock_open Sign Up
Showing Page:
3/3

Sign up to view the full document!

lock_open Sign Up
Unformatted Attachment Preview
An arithmetic sequence is a sequence, in which the difference between any two consecutive terms is the same, i.e., the difference is a constant. For example, the sequence that begins 1, 4, 7, 10, 13, 16, ... is an arithmetic sequence since the difference between consecutive terms is always 3. Write a Java program to generate arithmetic sequences. Your program will invoke 2 methods: one method to generate the arithmetic sequence and save it in a 1-dimensional array; and one method to print that 1-dimensional array. Write your program so that it will generate output similar to the sample output below: How many times do you want to find arithmetic sequences? -3 ERROR: Should be positive. REENTER: 3 What is the first number in the sequence: 5 What is the differ ence between consecutive terms: 3 How many numbers in the sequence (up to 1000): 17 The arithmetic sequence is: 5 8 11 14 17 20 23 2 ...
Purchase document to see full attachment
User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.
Studypool
4.7
Indeed
4.5
Sitejabber
4.4

Similar Documents