Upload files to "OOP/Java/Lab/Week9"
This commit is contained in:
parent
e9a4ce08c7
commit
cd43a87e9b
5 changed files with 99 additions and 0 deletions
20
OOP/Java/Lab/Week9/arrange_array.java
Normal file
20
OOP/Java/Lab/Week9/arrange_array.java
Normal file
|
@ -0,0 +1,20 @@
|
|||
|
||||
import java.util.*;
|
||||
|
||||
public class arrange_array {
|
||||
public static void main(String[] args) {
|
||||
int n;
|
||||
Scanner sc = new Scanner(System.in);
|
||||
System.out.println("Enter number of strings you would like");
|
||||
n = Integer.parseInt(sc.nextLine());
|
||||
System.out.println("Enter your strings");
|
||||
String[] arr = new String[n];
|
||||
for(int i = 0;i<n;i++){
|
||||
arr[i] = sc.nextLine();
|
||||
}
|
||||
Collections.sort(arr);// or use some sorting technique with arr[i].compareTo(arr[i+1])
|
||||
for(int i = 0;i<n;i++){
|
||||
System.out.print(arr[i]+" ");
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue