- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSortNumericAndStringArray.java
More file actions
Latest commit
28 lines (21 loc) · 735 Bytes
/
Copy pathSortNumericAndStringArray.java
File metadata and controls
28 lines (21 loc) · 735 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
packageBasics;
importjava.util.Arrays;
importjava.util.Scanner;
/**
* Write a Java program to sort a numeric array and a string array.
*/
publicclassSortNumericAndStringArray {
publicstaticvoidmain(String[] args) {
Scannerscanner = newScanner(System.in);
System.out.println("Enter number of elements in the array >");
intnumOfElements = scanner.nextInt();
String[] array = newString[numOfElements];
for (inti = 0; i < array.length; i++) {
System.out.println("Enter element " + (i+1));
array[i] = scanner.next();
}
Arrays.toString(array);
Arrays.sort(array);
System.out.println(Arrays.toString(array));
}
}