Documente Academic
Documente Profesional
Documente Cultură
This object includes the following operations and properties: Abs Cos ArcSin GetRandomNumber Floor Sin GetDegrees SquareRoot Log Remainder Min Pi
In this example, you get the sine and the cosine of an angle that you specify by using the Sin and Cos operations of the Math object. You can also get the angle in radians from the sine value by using the ArcSin operation. Next, you can convert the angle from radians to degrees with the GetDegrees operation.
The Pi Property
The value of pi is an important aspect of some mathematical calculations. You can retrieve the value of pi in your calculations by using the Pi property of the Math object.
In this example, you retrieve the value of pi by using the Pi property of the Math object. Then you use that value in the formula to get the area of the circle.
In this example, you subtract two numbers. Even if the first number is smaller than the second, the Abs operation returns a positive number.
Lets see how you can use this operation in a program to calculate a students average grade.
In this example, you enter the grades that a student earned in six subjects. Then, you use the Floor operation to get the students average as an integer value.
In this example, you use the Log operation to get the log value of 22.3.
In this example, you request two numbers from the user, use the Min operation to compare them, and display the smaller number in the text window. You also ensure that, if the user specifies the same number twice, the statement Both numbers are the same appears.
In this example, you specify a number and use the SquareRoot operation to get its square root.
In this program, you want to verify whether a specified number is even or odd. You use the If condition to verify whether the number is even (that is, whether the remainder is 0 when you divide the number by 2). If the remainder is 1, the number is odd. To check the remainder, you use the Remainder operation of the Math object.
Lets Summarize
By using the GetRandomNumber operation, write a program to move and rotate a rectangle in a random manner. Write a program to draw circles of different sizes in the graphics window. Set the size of the circle by using its area, and randomize the x-coordinates and y-coordinates of the circle.