Java returns NaN, an IEEE invention that means "Not a Number."
java.lang.Math.pow()
to raise zero to the zeroth power?
Java returns 1. Mathematically, this is incorrect. It should return NaN
.
package
statement in a Java source code file?Only comments.
import
statement in a Java source code file?Comments and package statements.
Absolutely.
public double sine(double degrees) {
double radians = degrees * Math.PI / 180.0;
return Math.sin(radians);
}
public double cosine(double degrees) {
double radians = degrees * Math.PI / 180.0;
return Math.cos(radians);
}
public double tangent(double degrees) {
double radians = degrees * Math.PI / 180.0;
return Math.tan(radians);
}
public double arcsine(double sine) {
return Math.asin(sine) * 180.0 / Math.PI;
}
public double arccosine(double cosine) {
return Math.acos(cosine) * 180.0 / Math.PI;
}
public double arctangent(double tangent) {
return Math.atan(tangent) * 180.0 / Math.PI;
}
public double sec(double radians) {
return 1.0/Math.cos(radians);
}
public double csc(double radians) {
return 1.0/Math.sin(radians);
}
public double ctn(double radians) {
return 1.0/Math.tan(radians);
}
public double log10(double x) {
return Math.log(x)/Math.log(10.0);
}
public double log2(double x) {
return Math.log(x)/Math.log(2.0);
}
public class bacteria {
public static void main(String args[]) {
try {
double p0 = Double.valueOf(args[0]).doubleValue();
double t = Double.valueOf(args[1]).doubleValue();
System.out.println(p0 * Math.exp(1.4 * t));
}
catch (Exception e) {
System.out.println("Usage: java bacteria initial_population num_hours");
}
}
}
public class bacteria {
public static void main(String args[]) {
try {
double p0 = Double.valueOf(args[0]).doubleValue();
double t = Double.valueOf(args[1]).doubleValue()/60.0;
System.out.println(p0 * Math.exp(1.4 * t));
}
catch (Exception e) {
System.out.println("Usage: java bacteria initial_population num_hours");
}
}
}
Write a Java application that calculates the age of an object given the percentage of carbon 14 remaining.
public class agefromC14 {
public static void main(String args[]) {
try {
double p0 = Double.valueOf(args[0]).doubleValue();
double age = -Math.log(p0/1.22E-4);
System.out.println(age);
}
catch (Exception e) {
System.out.println("Usage: java agefromC14 %_C14");
}
}
}