Use a variables of type double for the calculations

Assignment Help JAVA Programming
Reference no: EM13941426

(The following is exactly how the problem is presented)

import java.util.Scanner;
import java.text.DecimalFormat;

/**
Iteratively computes e^x for a given value x, outputing values at iteration
1 to 10, 50, and 100
*/
public class Ex {

public static void main(String[] args) {
// Make a Scanner to read data from the console
Scanner console = new Scanner(System.in);

// Make a NumberFormat object that we'll use when printing values
// of n in the loop below
DecimalFormat nFormat = new DecimalFormat("000");

// Read in a number for x
System.out.println("Enter a value for x (or a blank line to quit):");
String xString = console.nextLine();
while ((xString != null) && (xString.length() > 0)) {
double x = Double.parseDouble(xString);

// --------------------------------
// ----- ENTER YOUR CODE HERE -----
// --------------------------------

// --------------------------------
// --------- END USER CODE --------
// --------------------------------

// Start over again
System.out.println(
"Enter a value for x (or a blank line to quit):");
xString = console.nextLine();
}
}

}
The value ex can be approximated by the sum:
1 + x + x2/2! + x3/3! + ... + xn/n!
Write a program that takes a value x as input and outputs this sum for n taken to be each of the values 1 to 10, 50, and 100. Your program should repeat the calculation for new values of x until the user says she or he is through. The expression n! is called the factorial of n and is defined as
n! = 1 * 2 * 3 * ... * n
Define variables for the value of n! in the current iteration of the loop. Within the loop, you can then simply update this variable to be equal to the previous value multiplied by the value of the loop iterator. For example, if the loop iterator variable is n and the current factorial value is in variable fact, the following line will update the value of the factorial:
fact = fact * n;
The program should use a DecimalFormat object (local variable nFormat) to format the output. See Section 2.1 for more information on the DecimalFormat class.

Make sure that you use a variables of type double for the calculations in this project

Reference no: EM13941426

Questions Cloud

Property management department : How important is it to have strong processes and procedures in your Property Management department? Why and what are some processes relating to reception and tenants needs and briefly describe them?
Discuss specific symptoms children with adhd : Introduction: Write one to two pages in which you provide a summary of ADHD and discuss specific symptoms children with ADHD might demonstrate in the classroom and during play activities
Costs to register and issue securities : Direct and Indirect combination costs, Costs to register and issue securities.
Beta of stock : A stock has an expected return of 12.2 percent, the risk-free rate is 4 percent, and the market risk premium is 10 percent. What must the beta of this stock be?
Use a variables of type double for the calculations : Write a program that takes a value x as input and outputs this sum for n taken to be each of the values 1 to 10, 50, and 100
What is the value of the tax shield : Hastings Corporation is interested in acquiring Vandell Corporation. Vandell has 1 million shares outstanding and a target capital structure consisting of 30% debt; its beta is 1.20. What is the value of the unlevered firm? What is the value of the t..
Different combinations of the two goods : Consider a consumer who each week purchases two goods, X and Y. The following table shows three different combinations of the two goods that lie on three of her indifference curves-A,B, and C.
Capital markets-how does leverage affect cost of equity : In perfect capital markets, how does leverage affect the cost of equity? a. In perfect capital markets, levered equity's cost increases with the debt-equity ratio. b. In perfect capital markets, leverage increases the cost of levered equity by the co..
Combine the four loop problems into one program : Combine the four loop problems into one program with four distinct methods (the data is in the attached document). For this problem you will write methods, two value returning methods and two void methods.

Reviews

Write a Review

JAVA Programming Questions & Answers

  Java application-tests random number generation abilities

Write a Java application which tests the random number generation abilities of Java. Random number generation is explained below.

  Recursive factorial program

Write a class Array that encapsulates an array and provides bounds-checked access. Create a recursive factorial program that prompts the user for an integer N and writes out a series of equations representing the calculation of N!.

  Project is for designing and developing a college

project is for designing and developing a college registration program. write a java program to register students for a

  How can i connect from an applet to a database on the server

1) How do I create an applet that accepts an unlimited number of parameters? 2) How can I connect from an applet to a database on the server?

  Java code that needs to be coded-complex number class

Just a Java Code that needs to be coded. Your given the design, just needs the methods and such to be fixed. This is for a Complex Number class.

  Set of positive integers and outputs

Write a program that reads in a set of positive integers and outputs how many times a particular number appears in the list. You may assume that the data set has at most 100 numbers and -999 marks the end of the input data.

  Create a class for services offered by a hair-styling salon.

The Curl Up and Dye Salon offers a variety of salon services for its customers. Jane Fields, the owner, has contracted to have you write a program that allows reports to be output, sorted by each type of service offered. Table below shows the vari..

  Java program that prompts the user to input three numbers

Need a java program that prompts the user to input three numbers. This program should then output the numbers in nondescending order

  Problem related to eclips

Goals: 1) Be able to work with individual bits in java. 2) Understand the serializable interface. 3) Understand the comparable interface.

  Write a reference class called ctatrain

writing a reference class that consist of the 2nd and 3rd instance variables below. my class should consist of an array of values in the 2nd instance variable

  Create a world class that contains a 2d array

You have to create a world class that contains a 2d array then create an abstract class called organism that contains move() method the organism should move randomly one step at the time.

  Inheriting from the jframe class

What is the difference between inheriting from the JFrame class and using a JFrame member variable?

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd