Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Dart/factorial.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
int factorial(int num) {
if (num <= 1) {
return 1;
} else {
return num * factorial(num - 1);
}
}

void main() {
int number = 5;
int factorial = factorial(number);

print('The factorial of $number is $factorial');
}
3 changes: 3 additions & 0 deletions Dart/whileloop.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
while (!isDone()) {
doSomething();
}
27 changes: 27 additions & 0 deletions Java/BinarySearch/BinarySearchVariation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
public class BinarySearchVariation {
public static int indexOfFirstOccurrence(int[] nums, int target) {
int low = 0;
int high = nums.length - 1;

while (low <= high) {
int mid = (low + high) / 2;

if (nums[mid] == target && (mid == 0 || nums[mid - 1] != target)) {
return mid;
} else if (nums[mid] < target) {
low = mid + 1;
} else {
high = mid - 1;
}
}

return -1;
}
public static void main(String[] args){
int[] nums = {1, 3, 5, 5, 5, 7, 9};
int target = 5;

int indexOfFirstOccurrence = indexOfFirstOccurrence(nums, target);
System.out.println("Index of first occurrence: " + indexOfFirstOccurrence);//2
}
}
25 changes: 25 additions & 0 deletions Java/BinarySearch/BinarySearchVariationIndexOfLastOccurrence.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
public class BinarySearchVariationIndexOfLastOccurrence {
public static int indexOfLastOccurrence(int[] nums, int target) {
int low = 0;
int high = nums.length - 1;

while (low <= high) {
int mid = (low + high) / 2;

if (nums[mid] == target && (mid == nums.length - 1 || nums[mid + 1] != target)) {
return mid;
} else if (nums[mid] <= target) {
low = mid + 1;
} else {
high = mid - 1;
}
}

return -1;
}
public static void main(String [] args){
int[] nums = {1, 3, 5, 5, 5, 7, 9};
int target = 5;
int indexOfLastOccurrence = indexOfLastOccurrence(nums, target);
System.out.println("Index of last occurrence: " + indexOfLastOccurrence);//4
}
31 changes: 31 additions & 0 deletions stringexample.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Single-line string
String name = 'Alice';

// Multi-line string using double quotes
String greeting = "Hello, $name!";

// Multi-line string using triple quotes
String poem = """
Roses are red,
Violets are blue,
Sugar is sweet,
And so are you.
""";

// String interpolation
print('Your name is $name and your greeting is $greeting.');

// String concatenation
print('${name} says, "${greeting}"');

// String methods
String upperName = name.toUpperCase();
String lowerName = name.toLowerCase();
String trimmedName = name.trim();

// String comparison
if (name == 'Alice') {
print('Hello, Alice!');
} else {
print('Hello, stranger!');
}