Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please code it in JAVA and please don't add any System.out.print or any scanner class. An arithmetic sequence sn of size n, and a difference

Please code it in JAVA and please don't add any System.out.print or any scanner class.

image text in transcribedimage text in transcribed

image text in transcribed

An arithmetic sequence sn of size n, and a difference d can be defined as follows: sn=(t1,t2,t3,,tn)suchthatti=t1+(i1)dand1in In other words, the sequence has n terms, the first term of the sequence is t1, and the difference between each two consecutive terms is d. Implement a method called getSeqStat which takes as inputs 3 integer parameters: the first term (t1) of the sequence, a common difference (d), and size (n). The method should return a string value containing n items: { item 1, item 2,, item n} Each item i tem ii is a string that contains the sum and product of the sub-sequence (t1,,ti) with size (1in). For example: item 4 contains the sum and product of the sub-sequence (t1,t2,t3, t4) The String return value must conform to the following format for the items (item it 1 item 2,, , item n ): 1. All items are wrapped within curly braces ( \{\}) and separated by semicolons (;) and a space. 2. Each item is wrapped within square brackets ([]) and contains the sum and product of the corresponding sub-subsequence. 3. Subsequences are wrapped within angle brackets (). For example. the calls: - getseqStat (10,5,2) represents the sequence s3=(10,15). The first term is 10 , the difference is 5 and the size is 2 . The return string of the method should contain 2 items containing sum and product for the sequences (10), and (10,15). The output should look like this: {[10:10,10];[10,15:25,150]} Recall from the previous task, an arithmetic sequence is defined as follows: sn=(t1,t2,t3,,tn)suchthatti=t1+(i1)dand1in Write a method called seqInterleaving that takes as input the info of two sequences (f1, d1, n1) and (f2, d2, and n2) such that they represent the first terms, the differences, and the sizes of the 2 sequences. The method should return a string that represent a sequence containing the interleavings of the two sequences. For example, for the two sequences with the same length: (3,8) and (11,4). Their interleaving is (3,11,8,4), such that for every 2 terms, the first is from the first sequence and the second term is from the second sequence. your method should consider two arithmetic sequences of different lengths. For example, the interleaving of the sequences (1,3) and (10,20,30,40) is (1,10,3,20,30,40). Examples: - seqInterleaving (1,2,2,10,10,4) represents the two sequences (1,3) and (10,20,30,40). It should return the string: ) and separated by commas (,). There is one space after each comma. getSeqstat (4,6,5) represents the sequence ss=(4,10,16,22,28). The first term is 4 , the difference is 6 and the size is 5 . The return string of the method should contain 5 items containing sum and product for the sequences (4), (4,10),(4,10,16),(4,10,16,22), and (4, 10,16,22,28) The output would be: {[:4,4];[:14,40];[:30,640];[:52,14080];[:80,394240]} All items above should be wrapped within curly braces ({}) and separated by semicolons (;) and a space except the last item. There is one space after each comma (,) and colon (:) after each sequence

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

SQL Server T-SQL Recipes

Authors: David Dye, Jason Brimhall

4th Edition

1484200616, 9781484200612

More Books

Students also viewed these Databases questions