From 87d53fc902fbfb638b25de3637e8556d0a64f897 Mon Sep 17 00:00:00 2001 From: $onup <30662033+sonup97@users.noreply.github.com> Date: Thu, 19 Oct 2023 11:57:57 +0530 Subject: [PATCH 1/7] Create factorial.dart Basic Program using dart factorial --- Dart/factorial.dart | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 Dart/factorial.dart diff --git a/Dart/factorial.dart b/Dart/factorial.dart new file mode 100644 index 0000000..9f33cd7 --- /dev/null +++ b/Dart/factorial.dart @@ -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'); +} From f0b5c6b1f1c5ee38e77101fee3a571706f07275b Mon Sep 17 00:00:00 2001 From: $onup <30662033+sonup97@users.noreply.github.com> Date: Sun, 22 Oct 2023 12:57:50 +0530 Subject: [PATCH 2/7] Create whileloop.dart A while loop evaluates the condition before the loop. It is also called the entry loop --- Dart/whileloop.dart | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 Dart/whileloop.dart diff --git a/Dart/whileloop.dart b/Dart/whileloop.dart new file mode 100644 index 0000000..e9984c1 --- /dev/null +++ b/Dart/whileloop.dart @@ -0,0 +1,3 @@ +while (!isDone()) { + doSomething(); +} From 109e91af5e6293a3179d559b2282781712e38d83 Mon Sep 17 00:00:00 2001 From: $onup <30662033+sonup97@users.noreply.github.com> Date: Sun, 22 Oct 2023 13:00:31 +0530 Subject: [PATCH 3/7] Create doWhile.dart A do-while loop evaluates the condition after the loop. It is also called the exit loop --- Dart/doWhile.dart | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 Dart/doWhile.dart diff --git a/Dart/doWhile.dart b/Dart/doWhile.dart new file mode 100644 index 0000000..bc13091 --- /dev/null +++ b/Dart/doWhile.dart @@ -0,0 +1,3 @@ +do { + printLine(); +} while (!atEndOfPage()); From 4e7018a2296e0ad0a625930d2628e514a79f49bd Mon Sep 17 00:00:00 2001 From: $onup <30662033+sonup97@users.noreply.github.com> Date: Sun, 22 Oct 2023 13:17:14 +0530 Subject: [PATCH 4/7] Create BinarySearchVariation.java indexOfFirstOccurrence(): Finds the index of the first occurrence of the target element in the sorted array. If the target element does not exist in the array, the method returns -1. --- Java/BinarySearch/BinarySearchVariation.java | 27 ++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 Java/BinarySearch/BinarySearchVariation.java diff --git a/Java/BinarySearch/BinarySearchVariation.java b/Java/BinarySearch/BinarySearchVariation.java new file mode 100644 index 0000000..b58a121 --- /dev/null +++ b/Java/BinarySearch/BinarySearchVariation.java @@ -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 + } +} From 70a9475380c9c96a862cfb566f7acd5fcaa1aead Mon Sep 17 00:00:00 2001 From: $onup <30662033+sonup97@users.noreply.github.com> Date: Sun, 22 Oct 2023 13:25:18 +0530 Subject: [PATCH 5/7] Create BinarySearchVariationIndexOfLastOccurrence.java indexOfLastOccurrence(): Finds the index of the last occurrence of the target element in the sorted array. If the target element does not exist in the array, the method returns -1. --- ...ySearchVariationIndexOfLastOccurrence.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 Java/BinarySearch/BinarySearchVariationIndexOfLastOccurrence.java diff --git a/Java/BinarySearch/BinarySearchVariationIndexOfLastOccurrence.java b/Java/BinarySearch/BinarySearchVariationIndexOfLastOccurrence.java new file mode 100644 index 0000000..6419340 --- /dev/null +++ b/Java/BinarySearch/BinarySearchVariationIndexOfLastOccurrence.java @@ -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 + } From 0c576494609d70ef653e176996cc02b01032654d Mon Sep 17 00:00:00 2001 From: $onup <30662033+sonup97@users.noreply.github.com> Date: Sun, 22 Oct 2023 13:27:22 +0530 Subject: [PATCH 6/7] Revert "Create doWhile.dart" --- Dart/doWhile.dart | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 Dart/doWhile.dart diff --git a/Dart/doWhile.dart b/Dart/doWhile.dart deleted file mode 100644 index bc13091..0000000 --- a/Dart/doWhile.dart +++ /dev/null @@ -1,3 +0,0 @@ -do { - printLine(); -} while (!atEndOfPage()); From c09ba66ee24030f050df9760e74207715791b9d2 Mon Sep 17 00:00:00 2001 From: $onup <30662033+sonup97@users.noreply.github.com> Date: Sun, 22 Oct 2023 13:32:20 +0530 Subject: [PATCH 7/7] Create stringexample.dart example on dart programming language --- stringexample.dart | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 stringexample.dart diff --git a/stringexample.dart b/stringexample.dart new file mode 100644 index 0000000..fcf74a5 --- /dev/null +++ b/stringexample.dart @@ -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!'); +}