· initialize an arr[5] = {3,2,6,1,7 }
· pass the entire array to a method
‘sort’ to perform bubble sort.
· print the sorted array in your method.
Code:
import java.util.*;
public class Sorting
{
public static void main(String args[])
{
int a;
int arr[] = { 3,2,6,1,7 };
sort(arr);
}
static void sort(int n[])
{
Arrays.sort(n);
for (int x:n) /* for each loop*/
System.out.println(x);
}
}
Output:
No comments:
Post a Comment