3:53 pm - Tuesday March 25, 8797

Java Example Program for gemetric series

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044

/**
* @author : Arun
* @description:Geometric Series program.
*/
import java.lang.*;

public class Geo {
int a, r;

void Series() {
for (int i = 0; i <= 6; i++) // For loop to determine the number of
// terms in geometric series
{
double series = a * Math.pow(r, i); // Geometric series calculation
int s = (int) series; // converts double into integer value
System.out.println(s + "\n"); // Prints geometric values
}
}

public static void main(String[] args) {
Geo g = new Geo();
g.a = 2;
g.r = 3;
g.Series(); // Calling method Series
}
}

output:

2

6

18

54

162

486

1458

Filed in: Z-A All Java Codes

Comments are closed.