JAVA
import java.util.Arrays;
class Main {
public static void main(String[] args) {
int [] source = {1, 2, 3, 4, 5, 6};
int [] destination = new int[6];
// iterate and copy elements from source to destination
for (int i = 0; i < source.length; ++i) {
destination[i] = source[i];
}
// converting array to string
System.out.println(Arrays.toString(destination));
}
}
Explanation :
-
import java.util.Arrays;Imports the built-in utility classArraysfrom the standardjava.utilpackage, allowing access to helper methods likeArrays.toString()for array manipulation and display. -
class Main {Declares a class namedMain. In Java, all code must reside inside a class structure. -
public static void main(String[] args) {Defines the entry point of the Java application: -
public: Accessible from anywhere. -
static: Can be invoked without creating an instance ofMain. -
void: Does not return any value. -
main: Name of the standard startup method. -
String[] args: Accepts optional command-line arguments as an array of strings. -
int [] source = {1, 2, 3, 4, 5, 6};Declares and initializes an integer array namedsourcecontaining six elements:1, 2, 3, 4, 5, 6. -
int [] destination = new int[6];Allocates a new integer array nameddestinationof size 6. By default, Java initializes all its integer elements to0. -
// iterate and copy elements from source to destinationA single-line comment explaining the purpose of the subsequentforloop (ignored by the compiler). -
for (int i = 0; i < source.length; ++i) {Sets up a loop to iterate through each index of the array: -
int i = 0: Initializes loop indexiat 0 (the first element). -
i < source.length: Condition to keep looping whileiis less than6(indices 0 through 5). -
++i: Pre-incrementsiby 1 after each loop cycle. -
destination[i] = source[i];Copies the element at indexiof thesourcearray into the matching indexiof thedestinationarray. -
}Marks the end of theforloop body. -
// converting array to stringA single-line comment indicating that the array will be converted into a readable string format. System.out.println(Arrays.toString(destination));-
Arrays.toString(destination)converts thedestinationarray into a readable string representation:"[1, 2, 3, 4, 5, 6]". -
System.out.println(...)prints this string to the console followed by a newline. -
}Closes themainmethod. -
}Closes theMainclass definition.
SQL
SELECT TOP Clause
The SELECT TOP clause is used to limit the number of records to return.
The SELECT TOP clause is useful on large tables with thousands of records. Returning a large number of records can impact performance.
The following SQL selects only the first 3 records of the "Customers" table:
#Select only the first 3 records of the Customers table:
SELECT TOP 3 * FROM Customers;
References :
https://www.programiz.com/java-programming/copy-arrays
https://www.w3schools.com/sql/sql_top.asp
Top comments (0)