Java Arrays Examples
Java Arrays Examples
//array initialization
names[0]="Chaitanya";
names[1]="Ajeet";
names[2]="Rahul";
names[3]="Shivam";
names[4]="Rohit";
//int array
int numbers[]={1, 2, 3, 4, 5};
Example 5:
public class JavaExample{
public static void main(String args[]){
int number[]={1, 5, 7, 9, 11};
for(int i=0;i<=number.length;i++){
System.out.println(number[i]);
}
}
}
Solutions:
Sorting Array Elements
import java.util.Scanner;
public class JavaExample
{
public static void main(String[] args)
{
int count, temp;
//User inputs the array size
Scanner scan = new Scanner(System.in);
System.out.print("Enter number of elements you want in the array: ");
count = scan.nextInt();
class SortCharArray {
// Selective Sorting
/* public static void sort(char[] a, int fromIndex,
* int toIndex): Sorts the specified range of the
* array into ascending order. The range to be sorted
* extends from the index fromIndex, inclusive, to the
* index toIndex, exclusive. If fromIndex == toIndex,
* the range to be sorted is empty.
*/
Arrays.sort(charArray2, 2, 5);
??
Program to print duplicate elements of the String array
System.out.println(min);
}
class Main {
public static void main(String[] args) {