Java ME SDK 3.0 Math Class
We propose to write a JAVA program PrixLot1.java who plays the role of playmaker and the execution of this program you will take the role of the player. The program Prixlot1must set the price of the lot drawing a random integer between 1 and 1000 and dialogue with the player during the game. But i did not find Math Class in Java ME SDK 3.0. Any idea?
Re: Java ME SDK 3.0 Math Class
To choose a random number we will use the random class Math , which returns a real (double) randomly and uniformly in the interval [0 1]
example
Code:
double x;
x = Math.random ();
example of running the program PrixLot1
Code:
Eudoxus% java PrixLot1
The goal is to seek a price between 0 and 1000
Enter a price: 566
Too
Enter a price: 400
Too
Enter a price: 150
Too small
Enter a price: 200
Too small
Enter a price: 214
BRAVO You have won five trials
Eudoxus%
Re: Java ME SDK 3.0 Math Class
Here is the description of different "tools" that can allow you to make mathematical calculations. The first two classes are part of the standard JDK, the latter is an API of Jakarta Commons project.Math (package java.lang): The Math class contains a set of static methods to do basic numerical operations (logarithms, exponential or trigonometric functions). Unlike the class StrictMath, different implementations of the same method does not give the same result "bitwise". We can nevertheless note that, generally, implementations of the methods of the Math class to call methods StrictMath. If accuracy is not paramount, you may prefer to StrictMath Math for performance reasons.
Re: Java ME SDK 3.0 Math Class
# StrictMath (package java.lang): StrictMath methods are the same as Math, unlike the results obtained are the same as those produced by fdlibm (Freely Distributable Math Library). More in the class description StrictMath: http://java.sun.com/j2se/1.5.0/docs/...trictMath.html
# Math 1.0 (Jakarta Commons): This API (available at: http://jakarta.apache.org/commons/math/) provides the Java developer a greater number of mathematical and statistical algorithms. More information in the documentation: http://jakarta.apache.org/commons/ma...ide/index.html.
Re: Java ME SDK 3.0 Math Class
Java.lang.Math class contains a series of mathematical methods and variables. As the Math class is part of the java.lang package, it is automatically imported. Moreover, it is not necessary to declare an object of type Math because the methods are all static
Example (Java 1.1):
Code:
Calculate and display the square root of 3
public class math1 (
public static void main (java.lang.String[] args) (System.out.println ("=" + Math.sqrt (3.0));))
Re: Java ME SDK 3.0 Math Class
Methods sin () cos () tan (), asin (), acos () atan () is declared: public static double fonctiontrigo (double angle). The angles must be expressed in radians. To convert degrees to radians, simply multiply by PI/180. These methods exist for the types int, long, float and double: they determine respectively the maximum and minimum values of two parameters.
Code:
public class math1
public static void main (String[] args) (System.out.println ("biggest =" + Math.max (5, 10)) System.out.println ("the smallest =" + Math.min (7, 14));))
Result:
largest = 10 = 7 the smallest