3.4 做不出
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.IOException;
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) throws IOException {
// Make a BufferedReader to read data from the console
BufferedReader console = new BufferedReader(
new InputStreamReader(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.readLine();
while ((xString != null) && (xString.length() > 0)) {
double x = Double.parseDouble(xString);
// --------------------------------
// ----- ENTER YOUR CODE HERE -----
// --------------------------------
System.out.println("input n=1 to 10, 50, and 100");
int n = Integer.parseInt(console.readLine());
int a= 1 ;
for (int nj=1 ;nj<=n ;nj++)
a=a*x/nj
y=a+b
// --------------------------------
// --------- END USER CODE --------
// --------------------------------
// Start over again
System.out.println(
"Enter a value for x (or a blank line to quit):");
xString = console.readLine();
}
}
}
import java.io.BufferedReader;
import java.io.IOException;
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) throws IOException {
// Make a BufferedReader to read data from the console
BufferedReader console = new BufferedReader(
new InputStreamReader(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.readLine();
while ((xString != null) && (xString.length() > 0)) {
double x = Double.parseDouble(xString);
// --------------------------------
// ----- ENTER YOUR CODE HERE -----
// --------------------------------
System.out.println("input n=1 to 10, 50, and 100");
int n = Integer.parseInt(console.readLine());
int a= 1 ;
for (int nj=1 ;nj<=n ;nj++)
a=a*x/nj
y=a+b
// --------------------------------
// --------- END USER CODE --------
// --------------------------------
// Start over again
System.out.println(
"Enter a value for x (or a blank line to quit):");
xString = console.readLine();
}
}
}
0 Comments:
Post a Comment
<< Home