Page 165 - computer science (868) class 11
P. 165
2. Using this function, we can generate a random number between m and (n -1).
Say, m=2, n=9;
int i = (int)(Math.random() * (n – m));
[It will return any integer number from 2 to 8]
14. Trigonometrical Functions
In Java, there are three trigonometrical functions:
• Math.sin()
• Math.cos()
• Math.tan()
In the above methods, the arguments are passed in Radians which are generally derived from degrees. We can
convert degree into radian by using the following formula:
Radian = (π * degree given)/180.0
For example:
If double degree = 60, radian;
radian = (22.0/7.0*60)/180.0 = 1.0476
Example 1: double r = Math.rint(Math.sin(Radian)); Output : 1.0
Example 2: double r = Math.rint(Math.cos(Radian)); Output : 0.0
Example 3: double r = Math.rint(Math.tan(Radian)); Output : 2.0
#Creativity & Innovativeness
Some More Programs
#Interdisciplinary
Program 1 Write a program in Java to input three numbers and print the second greatest number.
1 import java.util.*;
2 class secondgreatest_number
3 {
4 public static void main()
5 {
6 Scanner sc= new Scanner(System.in);
7 double a,b,c;
8 System.out.print("Enter three numbers :");
9 a= sc.nextDouble();
10 b= sc.nextDouble();
11 c= sc.nextDouble();
12 System.out.println("--------------------------");
13 if((a>b) && (a>c))
163
Statements and Scope 163

