diff --git a/ujjwamishraCSE27/RemoveDuplicates.java b/ujjwamishraCSE27/RemoveDuplicates.java new file mode 100644 index 0000000..c8bae88 --- /dev/null +++ b/ujjwamishraCSE27/RemoveDuplicates.java @@ -0,0 +1,39 @@ +import java.util.Scanner; + +public class RemoveDuplicates { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + + System.out.print("Enter the number of elements: "); + int n = sc.nextInt(); + int[] nums = new int[n]; + + System.out.print("Enter the sorted elements: "); + for (int i = 0; i < n; i++) { + nums[i] = sc.nextInt(); + } + + + if (n == 0) { + System.out.println("Unique count: 0"); + return; + } + + int k = 1; + + for (int i = 1; i < n; i++) { + if (nums[i] != nums[k - 1]) { + nums[k] = nums[i]; + k++; + } + } + + + System.out.println("Unique count: " + k); + System.out.print("Modified array: "); + for (int i = 0; i < k; i++) { + System.out.print(nums[i] + " "); + } + System.out.println(); + } +} diff --git a/ujjwamishraCSE27/TwoSum.java b/ujjwamishraCSE27/TwoSum.java new file mode 100644 index 0000000..fa03a32 --- /dev/null +++ b/ujjwamishraCSE27/TwoSum.java @@ -0,0 +1,42 @@ +import java.util.Scanner; + +public class TwoSum { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + + + System.out.print("Enter the number of elements: "); + int n = sc.nextInt(); + int[] nums = new int[n]; + + + System.out.print("Enter the elements: "); + for (int i = 0; i < n; i++) { + nums[i] = sc.nextInt(); + } + + + System.out.print("Enter the target sum: "); + int target = sc.nextInt(); + + + int i, j; + boolean found = false; + + for (i = 0; i < n; i++) { + for (j = i + 1; j < n; j++) { + if (nums[i] + nums[j] == target) { + System.out.println("Output: [" + i + ", " + j + "]"); + found = true; + break; + } + } + if (found) break; + } + + if (!found) { + System.out.println("No two elements found that sum up to target."); + } + } +} +