The java.util.Scanner class is a simple text scanner which can parse primitive types and strings using regular expressions.Following are the important points about Scanner:
1-A Scanner breaks its input into tokens using a delimiter pattern, which by default matches whitespace.
2-A scanning operation may block waiting for input.
3-A Scanner is not safe for multithreaded use without external synchronization.
package com.indra;
import java.util.Scanner;
public class TangentProgram {
public static void main(String[] hh) {
Scanner sc = new Scanner(System.in);
for (int i = 0; i >= 0; i++) {
System.out.println("1 for sin value\n2 for cos value\n3 for tan value\n4 for cot value\n5 for sec value\n6 for cosec value\n7 for square\n8 for square root\n9 1/square root");
int operator = sc.nextInt();
System.out.println("Enter the value of theta");
double theta = sc.nextDouble();
switch (operator) {
case 1:
System.out.println("Answer is - "
+ Math.sin(Math.toRadians(theta)));
break;
case 2:
System.out.println("Answer is - "
+ Math.cos(Math.toRadians(theta)));
break;
case 3:
System.out.println("Answer is - "
+ Math.tan(Math.toRadians(theta)));
break;
case 4:
System.out.println("Answer is - "
+ (1 / Math.tan(Math.toRadians(theta))));
break;
case 5:
System.out.println("Answer is - "
+ (1 / Math.cos(Math.toRadians(theta))));
break;
case 6:
System.out.println("Answer is - "
+ (1 / Math.sin(Math.toRadians(theta))));
break;
case 7:
System.out.println("Answer is - " + theta * theta);
break;
case 8:
System.out.println("Answer is - " + theta * theta * theta);
break;
case 9:
System.out.println("Answer is - " + (Math.sqrt(theta)));
break;
case 10:
System.out.println("Answer is - " + (Math.cbrt(theta)));
break;
default:
break;
}
}
}
}
No comments:
Post a Comment