0% found this document useful (0 votes)
35 views3 pages

Java Code To: Find Out SQ RT, Log or Factorial of A Number, Then Return The Results

This Java code defines classes and methods to calculate the logarithm, factorial, and square root of a user-input number. The user is prompted to select an operation, then input a number, after which the corresponding method calculates and prints the result. The code takes a number as input, calls the appropriate method based on the user's selection, performs the calculation, and returns the output.

Uploaded by

Yohannes Abrha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views3 pages

Java Code To: Find Out SQ RT, Log or Factorial of A Number, Then Return The Results

This Java code defines classes and methods to calculate the logarithm, factorial, and square root of a user-input number. The user is prompted to select an operation, then input a number, after which the corresponding method calculates and prints the result. The code takes a number as input, calls the appropriate method based on the user's selection, performs the calculation, and returns the output.

Uploaded by

Yohannes Abrha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Java Code to find out sqrt, 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();
}
}

You might also like