Series - int n=input.nextInt(); i double factorial=1;...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
/*The purpose of this class is to calculate and print out the value of y the sum of the terms in a series when the user enters the values of x and n.*/ w import java.util.Scanner; i public class Series { public static void main(String[]args) { Scanner input=new Scanner(System.in); System.out.println("Enter x:"); double x=input.nextDouble(); System.out.println("Enter the number of terms:");
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: int n=input.nextInt(); i double factorial=1; double y = 1+x; if((n<0)|(x<=0)|(x>10)) { System.out.println("Error! x must satisfy 0<=x<10, and n grater than 0."); } else { for(int i=2;i<=n;i++) { double a= Math.pow(x,i); factorial=factorial*i; y = y+(a/factorial); } System.out.printf("y=%5.3f",y); } } }...
View Full Document

This document was uploaded on 04/14/2010.

Ask a homework question - tutors are online