adplus-dvertising
Coders Packet

JAVA SERIES (LOOPS)

By Aamna Alam

In this tutorial we will use the integers x,y&n for the creation of series: (x+2⁰.y), (x+2⁰.y+2¹.y),..,(x+2⁰.y+2¹.y+...+(2^(n-1)).y), here we are given q queries in the form of x,y&n.

CONCEPT BEHIND THE PROBLEM:

Suppose we have 2 queries (q=2),

In query1: we have x=1, y=2, n=3

S0=1+1.2=3

S1=1+1.2+2.2=7

S2=1+1.2+2.2+4.2=15

 

In query2: we have x=5, y=3, n=4

S0=5+1.3=8

S1=5+1.3+2.3=14

S2=5+1.3+2.3+4.3=26

S3=5+1.3+2.3+4.3+8.3=50

example, Input:  2

                             1 2 3

                             5 3 4

Output : 3 7 15

              8 14 26 50

STEPS:

1)We start a loop till q (number of queries) times.

2)For each iteration in the loop we take user inputs for the parameters x,y and n.

3)We initialize the first sum value to the value of x (sm=x).

4)We start the loop (n-1)times and append ((2^n).y) to the sum series.

(sm=sm + (int)(Math.pow(2,i)*b);

5)We print the series.

Download Complete Code

Comments

No comments yet

Download Packet

Reviews Report

Submitted by Aamna Alam (aamnaalam)

Download packets of source code on Coders Packet