Created
October 19, 2015 09:29
-
-
Save joicemjoseph/da824ae7cc941d0b9500 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
//import java.util.Arrays; | |
class ArraySort | |
{ | |
int n,temp,num[]; | |
void read() | |
{ | |
Scanner s = new Scanner(System.in); | |
System.out.print("Enter n :"); | |
n = s.nextInt(); | |
num = new int[n]; | |
System.out.println("Enter the numbers :"); | |
for (int i=0; i<n; i++) | |
{ | |
num[i] = s.nextInt(); | |
} | |
} | |
void sort() | |
{ | |
for (int i=0; i<n-1; i++) | |
{ | |
for (int j=0; j<n-1; j++) | |
{ | |
if (num[j] > num[j+1]) | |
{ | |
temp = num[j]; | |
num[j] = num[j+1]; | |
num[j+1] = temp; | |
} | |
} | |
} | |
//Arrays.sort(num); | |
} | |
void display() | |
{ | |
for (int i : num) | |
{ | |
System.out.print(i + " "); | |
} | |
} | |
} | |
class Array | |
{ | |
public static void main(String[] args) | |
{ | |
ArraySort arraySort = new ArraySort(); | |
arraySort.read(); | |
arraySort.sort(); | |
System.out.print("Sorted list :"); | |
arraySort.display(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
import java.util.Arrays; | |
class ArraySort | |
{ | |
int temp; | |
public int[] num; | |
ArraySort() | |
{ | |
//num = new int[]{1,2,3}; | |
//num = new int[10]; | |
} | |
void sort() | |
{ | |
/*for (int i=0; i<num.length-1; i++) | |
{ | |
for (int j=0; j<num.length-i; j++) | |
{ | |
if (num[j] > num[j+1]) | |
{ | |
temp = num[j]; | |
num[j] = num[j+1]; | |
num[j+1] = temp; | |
} | |
} | |
} | |
*/ | |
Arrays.sort(num); | |
} | |
void display() | |
{ | |
/*for (int i=0; i<num.length; i++) | |
{ | |
System.out.print(num[i] + " "); | |
} | |
*/ | |
for (int i : num) | |
{ | |
System.out.print(i + " "); | |
} | |
} | |
} | |
class Array | |
{ | |
public static void main(String[] args) | |
{ | |
ArraySort arraySort = new ArraySort(); | |
int n; | |
Scanner s = new Scanner(System.in); | |
System.out.print("Enter n :"); | |
n = s.nextInt(); | |
arraySort.num = new int[n]; | |
System.out.print("Enter the numbers :"); | |
for (int i=0; i<n; i++) | |
{ | |
//String t = s.next(); | |
//arraySort.num[i] = Integer.parseInt(t); | |
arraySort.num[i] = s.nextInt(); | |
} | |
/*while (s.hasNextInt()) | |
{ | |
arraySort.num[i] = s.nextInt(); | |
i++; | |
} | |
*/ | |
/* | |
String[] arr = s.nextLine().split(" "); | |
for (i=0; i<arr.length; i++) | |
{ | |
arraySort.num[i] = Integer.parseInt(arr[i]); | |
} | |
*/ | |
arraySort.sort(); | |
System.out.print("Sorted list :"); | |
arraySort.display(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment