-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprojectB.java
More file actions
52 lines (35 loc) · 1.32 KB
/
Copy pathprojectB.java
File metadata and controls
52 lines (35 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import java.util.Scanner;
public class projectB {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter a number :");
int input = scanner.nextInt();
int result = factorial(input);
System.out.println("Factorial of " + input + " is: " + result);
int square = input * input;
System.out.println("Result: " + square);
double absresult = absoluteVal(input);
System.out.println("The Result is : " + absresult);
if (input % 2 == 0) {
System.out.println("even");
}
System.out.println("odd");
// power Function
System.out.println("Enter the base number for power calculation: ");
double base = scanner.nextDouble();
System.out.println("Enter the exponent number for power calculation: ");
double exponent = scanner.nextDouble();
double powerResult = Math.pow(base, exponent);
System.out.println(" The result is " + powerResult);
}
public static double absoluteVal(double number) {
return (number < 0) ? -number : number;
}
public static int factorial(int number) {
int result = 1;
for (int i = number; i > 0; i--) {
result *= i;
}
return result;
}
}