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

  Q1write a program called linearstringsearchjava that looks

q1.write a program called linearstringsearch.java that looks for a target string value in an array of string values.

  Write an app to test class integerset

Create class IntegerSet. Each IntegerSet object can hold integers in the range 0-100. The set is represented by an array of bools. Array element

  Eax contains the given contents before the instruction

For each add instruction in this problem, assume that EAX contains the given contents before the instruction is executed, and give the contents of EAX as well as the values of the CF, OF, SF, and ZF flags after the instruction is executed:

  Create a function that multiplies numeric matrices

Create a function that multiplies numeric matrices on an element-by-element basis.

  Calculate and display the mortgage payment amount

Change request7RequestorNinfa Pendleton - Rapid City, SDDescriptionWrite the program in Java (with a graphical user interface) and have it calculate and display the mortgage payment amount from user input of the amount of the mortgage

  Create a query that lists the number of appointments

Create a query that lists the number of appointments for each doctor by day. Display the number of appointments, the doctor ID, and the appointment date. Display the output in order of doctor ID with the lowest doctor ID first.

  Will the direction and magnitude be integers or doubles

Define a Physics_vector class which consists of a struct containing the direction and magnitude, and also define a function

  Write program in java to calculate interest

Write a program in java to do the following : the following data is stored for each customer in the bank: account number,average balance and number of transaction for each customer it is required to calculate the interest earn

  User enters a list of car parts

So if the user enters a list of car parts, the programm holds this list. Afterward, when the user types in the name of the part the programm outputs that name from the list.

  Write a program to store in a 2-d boolean array

Write a program to store in a 2-D boolean array of size 5 and 10 a true value if a random value is less than 0.5 else false. Print only the indexes of cells with true value.

  The program reads in names

Write a program and include the following methods. The program reads in names and ages (use 2 parallel arrays, maximum size 50) from a file called Stuff.dat.

  Hunt the wumpus game

Reprot on Hunt the Wumpus Game has Source Code listing, screen captures and UML design here and also, may include Javadoc source here.

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