fix: added a new challenge

This commit is contained in:
Sami 2024-11-07 10:14:19 -05:00
parent 880f1d5854
commit 8906e857ea
2 changed files with 48 additions and 17 deletions

Binary file not shown.

View File

@ -1,30 +1,61 @@
// public class ArrayReversing {
// public static void main(String[] args) {
// int[] intArr = { 1, 2, 3, 4, 5 };
// Reverse(intArr);
// Printing(intArr);
// }
//
// public static void Reverse(int[] arr) {
// // initiate the start and the end of the ArrayReversing
// int start = 0;
// int end = arr.length - 1;
//
// while (start < end) {
// int temp = arr[start];
// arr[start] = arr[end];
// arr[end] = temp;
// // Moving pointers
// start++;
// end--;
// }
// }
//
// public static void Printing(int[] arr) {
// for (int x : arr) {
// System.out.println(x + " ");
// }
// System.out.println();
// }
//
// }
/**
* ArrayReversing
*/
public class ArrayReversing {
public static void main(String[] args) {
int[] intArr = { 1, 2, 3, 4, 5 };
Reverse(intArr);
Printing(intArr);
}
public static void Reverse(int[] arr) {
// initiate the start and the end of the ArrayReversing
public static void main(String[] args) {
int[] numbers = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
// revNumbers = {10,9,8,7,6,5,4,3,2,1}
for (int i : numbers) {
System.out.print(i + "\t");
}
System.out.println();
int start = 0;
int end = arr.length - 1;
int end = numbers.length - 1;
while (start < end) {
int temp = arr[start];
arr[start] = arr[end];
arr[end] = temp;
// Moving pointers
int temp = numbers[start];
numbers[start] = numbers[end];
numbers[end] = temp;
start++;
end--;
}
}
public static void Printing(int[] arr) {
for (int x : arr) {
System.out.println(x + " ");
for (int x : numbers) {
System.out.print(x + "\t");
}
System.out.println();
}
}
}