#javaclass #java #javatutorial #javaforbeginners
Clear Code:
import java.util.Arrays;
class App {
public static void main(String[] args) {
// 1. length
int[] numbers = {10, 20, 30, 40, 50};
int length = numbers.length;
System.out.println("Length of the array: " + length);
// 2. copyOf
int[] original = {1, 2, 3, 4, 5};
int[] copy = Arrays.copyOf(original, 3);
System.out.println("Original array: " + Arrays.toString(original));
System.out.println("Copy of original array with length 3: " + Arrays.toString(copy));
// 3. sort
int[] unsortedNumbers = {5, 3, 8, 2, 7};
Arrays.sort(unsortedNumbers);
System.out.println("Sorted array: " + Arrays.toString(unsortedNumbers));
// 4. toString
int[] arrayToConvert = {1, 2, 3, 4, 5};
String arrayString = Arrays.toString(arrayToConvert);
System.out.println("Array as a string: " + arrayString);
// 5. binarySearch
int[] sortedNumbers = {2, 4, 6, 8, 10};
int index = Arrays.binarySearch(sortedNumbers, 6);
System.out.println("Index of element 6 in the sorted array: " + index);
}
}
Clear Code:
import java.util.Arrays;
class App {
public static void main(String[] args) {
// 1. length
int[] numbers = {10, 20, 30, 40, 50};
int length = numbers.length;
System.out.println("Length of the array: " + length);
// 2. copyOf
int[] original = {1, 2, 3, 4, 5};
int[] copy = Arrays.copyOf(original, 3);
System.out.println("Original array: " + Arrays.toString(original));
System.out.println("Copy of original array with length 3: " + Arrays.toString(copy));
// 3. sort
int[] unsortedNumbers = {5, 3, 8, 2, 7};
Arrays.sort(unsortedNumbers);
System.out.println("Sorted array: " + Arrays.toString(unsortedNumbers));
// 4. toString
int[] arrayToConvert = {1, 2, 3, 4, 5};
String arrayString = Arrays.toString(arrayToConvert);
System.out.println("Array as a string: " + arrayString);
// 5. binarySearch
int[] sortedNumbers = {2, 4, 6, 8, 10};
int index = Arrays.binarySearch(sortedNumbers, 6);
System.out.println("Index of element 6 in the sorted array: " + index);
}
}
- Категория
- Программирование на java
- Теги
- programming, coding, javaprogramming
Комментариев нет.