Java Code To: Find Out SQ RT, Log or Factorial of A Number, Then Return The Results
Java Code To: Find Out SQ RT, Log or Factorial of A Number, Then Return The Results
import java.util.*;
interface Defination
public void LogValue ();
public void Factorial ();
public void SquareRoot ();
}
class Operation implements Defination
{
public void Factorial ()
{
System.out.println("Find a Factorial, Enter The Number: ");
Scanner obj= new Scanner(System.in);
long input=obj. nextInt ();
long factorial=1;
for (long j=input>=1;j--)
{
factorial=factorial*j;
}
System.out.println("The Factorial OF "+input+" is "+factorial);
}
public void SquareRoot ()
{
Scanner obj=new Scanner(System.in);
System.out.print("Enter The Number for SquareRoot Value ");
double input =obj. nextInt ();
double output = Math.sqrt(input);
System.out.println("The square Root value of "+input+" is "+output);
}
}
class Choice extends Operation
{
public void Disp()
{
Scanner obj=new Scanner(System.in);
loop: while(true)
{
System.out.println("\n\please Chose The operation:\n");
System.out.println(" 1. Value of Log");
System.out.println(" 2. Factorial");
System.out.println(" 3. SquareRoot");
System.out.println(" 4. Exit\n");
System.out.print("Enter The Choice Number: ");
int input =obj. nextInt ();
switch(input)
{
case 1:
LogValue ();
break;
case 2:
Factorial ();
break;
case 3:
SquareRoot ();
break;
case 4:
break loop;
default:
System.out.println(“! Please Enter Valid Number !");
}
}
}
}
public class Calculator
{
public static void main (String [] arg)
{
Choice obj=new Choice ();
obj. Disp();
}
}