-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3c75905
commit f032874
Showing
83 changed files
with
2,434 additions
and
772 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
public class Filter { | ||
|
||
public static void filterdArray(int[] arr) { | ||
//! filtering process | ||
for(int i = 0; i < arr.length - 1; i++) { | ||
if(arr[i] % 2 != 0) | ||
System.out.print(arr[i] + " "); | ||
} | ||
} | ||
|
||
|
||
|
||
public static void main(String[] args) { | ||
int[] arr = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; | ||
filterdArray(arr); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<module type="JAVA_MODULE" version="4"> | ||
<component name="NewModuleRootManager" inherit-compiler-output="true"> | ||
<exclude-output /> | ||
<content url="file://$MODULE_DIR$"> | ||
<sourceFolder url="file://$MODULE_DIR$/Java-Programs" isTestSource="false" /> | ||
</content> | ||
<orderEntry type="inheritedJdk" /> | ||
<orderEntry type="sourceFolder" forTests="false" /> | ||
</component> | ||
</module> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
public class Max { | ||
public static void max(int[] arr) { | ||
int max = 0; | ||
for(int i = 0; i < arr.length; i++) { | ||
if(arr[i] > max) | ||
max = arr[i]; | ||
} | ||
|
||
System.out.println(max); | ||
} | ||
|
||
public static void main(String[] args) { | ||
int[] arr = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; | ||
max(arr); | ||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import java.util.*; | ||
|
||
class Practice { | ||
public static void main(String[] args) { | ||
ArrayList<Integer> arr = new ArrayList<>(); | ||
|
||
arr.add(4); | ||
arr.add(5); | ||
arr.add(8); | ||
arr.add(9); | ||
arr.add(3); | ||
arr.add(7); | ||
|
||
int target = 4; | ||
|
||
for (int i = 0; i < arr.size(); i++) { | ||
if (arr.get(i) == target) { | ||
arr.remove(arr.get(i)); | ||
} | ||
} | ||
|
||
int first = 0; | ||
int end = arr.size() - 1; | ||
int mid = (first + end) / 2; | ||
|
||
while (mid < end) { | ||
if (arr.get(first) < arr.get(mid)) { | ||
first++; | ||
} | ||
|
||
if (arr.get(first) > arr.get(mid)) { | ||
int temp = arr.get(first); | ||
arr.add(first, arr.get(mid)); | ||
arr.add(mid, temp); | ||
|
||
first++; | ||
} | ||
|
||
if (arr.get(mid) < arr.get(end)) { | ||
end--; | ||
} | ||
|
||
if (arr.get(mid) > arr.get(end)) { | ||
int temp = arr.get(mid); | ||
arr.add(mid, arr.get(end)); | ||
arr.add(end, temp); | ||
|
||
end--; | ||
} | ||
} | ||
|
||
System.out.println("List" + arr); | ||
System.out.println("Sorted List" + arr); | ||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
public class Sum_Array { | ||
public static void sum(int[] array) { | ||
int sum = 0; | ||
for(int i = 0; i < array.length - 1; i++) { | ||
sum += array[i]; | ||
} | ||
System.out.println(sum); | ||
} | ||
|
||
public static void main(String[] args) { | ||
int[] array = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; | ||
sum(array); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,42 @@ | ||
package arrays; | ||
|
||
/* Problem Title :-> find common elements in 3 sorted arrays */ | ||
/* Problem Title: Find common elements in 3 sorted arrays */ | ||
public class Array_Problem_19 { | ||
// This function prints common elements in a1 | ||
void findCommon(int[] a1, int[] a2, int[] a3) { | ||
// Initialize starting indexes for a1[], a2[] and a3[] | ||
int i = 0, j = 0, k = 0; | ||
// Iterate through three arrays while all arrays have elements | ||
while (i < a1.length && j < a2.length && k < a3.length) { | ||
// if x = y and y = z, print any of them and move ahead in all arrays | ||
if (a1[i] >= a2[j] && a2[j] == a3[k]) { | ||
System.out.print(a1[i] + " "); | ||
i++; | ||
k++; | ||
|
||
// This function prints common elements in firstArray | ||
void findCommon(int[] firstArray, int[] secondArray, int[] thirdArray) { | ||
// Initialize starting indices for arrays | ||
int firstIndex = 0, secondIndex = 0, thirdIndex = 0; | ||
|
||
// Iterate through arrays while all have elements | ||
while (firstIndex < firstArray.length && secondIndex < secondArray.length && thirdIndex < thirdArray.length) { | ||
// If elements are equal, print any and move forward in all arrays | ||
if (firstArray[firstIndex] == secondArray[secondIndex] && secondArray[secondIndex] == thirdArray[thirdIndex]) { | ||
System.out.print(firstArray[firstIndex] + " "); | ||
firstIndex++; | ||
thirdIndex++; | ||
} else if (firstArray[firstIndex] < secondArray[secondIndex]) { | ||
// First element is smaller, so move its index | ||
firstIndex++; | ||
} else if (secondArray[secondIndex] < thirdArray[thirdIndex]) { | ||
// Second element is smaller, so move its index | ||
secondIndex++; | ||
} else { | ||
// Third element is smaller, so move its index | ||
thirdIndex++; | ||
} | ||
// x < y | ||
else if (a1[j] < a2[j]) | ||
i++; | ||
// y < z | ||
else if (a2[j] < a3[k]) | ||
j++; | ||
// we reach here whem x > y and z < y, i.e., z is smallest | ||
else | ||
k++; | ||
} | ||
} | ||
|
||
/* Driver Code */ | ||
public static void main(String[] args) { | ||
|
||
Array_Problem_19 ob = new Array_Problem_19(); | ||
int a1[] = { 1, 5, 10, 20, 40, 80 }; | ||
int a2[] = { 6, 7, 20, 80, 100 }; | ||
int a3[] = { 3, 4, 15, 20, 30, 70, 80, 120 }; | ||
|
||
Array_Problem_19 object = new Array_Problem_19(); | ||
int[] firstArray = {1, 5, 10, 20, 40, 80}; | ||
int[] secondArray = {6, 7, 20, 80, 100}; | ||
int[] thirdArray = {3, 4, 15, 20, 30, 70, 80, 120}; | ||
|
||
System.out.print("Common elements are "); | ||
ob.findCommon(a1, a2, a3); | ||
object.findCommon(firstArray, secondArray, thirdArray); | ||
} | ||
} |
Oops, something went wrong.