Aldorithm and Code
Aldorithm and Code
PRIMITIVE NON-PRIMITIVE
These are the basic built-in data types These are custom or reference types created
provided by the programming language. using classes, arrays, or interfaces.
A primitive data type directly holds the value A non-primitive data type stores a reference
assigned to it (e.g., an int directly holds an (memory address) to the actual object rather
integer value). than the value itself.
The memory used is highly efficient and Objects may also have additional overhead
optimized. due to their reference nature.
Step 0: Initialization
Let sum = 0
Let count = 0
o Add x to sum
o Increase count by 1
Initialize squared_diff_sum = 0
o diff = x - mean
This is my code
import java.util.Scanner;
int n = scanner.nextInt();
numbers[i] = scanner.nextDouble();
double sum = 0;
for (double x : numbers) {
sum += x;
double squaredDiffSum = 0;
squaredDiffSum += diffSquared;
scanner.close();
}
This is the output
STANDARD DEVIATION
Step 0: Initialize
o Add x to sum
o Increase count by 1
Set squared_diff_sum = 0
o diff = x - mean
🔶 Step 6: Output
Display std_dev
THIS IS MY CODE
import java.util.Scanner;
// Input
int n = scanner.nextInt();
data[i] = scanner.nextDouble();
double sum = 0;
sum += num;
double squaredDiffSum = 0;
for (double num : data) {
// Output
scanner.close();
THIS IS MY OUTPUT
FACTORIAL
Input: A positive integer n
Output: The factorial of n (i.e., n! = n × (n-1) × ... × 1)
🔶 Step 0: Initialize
Let result = 1
Let step = n
o Decrease step by 1
🔶 Step 2: Output
THIS IS MY OUTPUT