Created
March 13, 2014 06:07
-
-
Save JorgeOlvera/9522647 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
/*1. Write a method dedup that reads strings from standard | |
input and prints them on standard output with all duplicates | |
removed (in sorted order).*/ | |
import java.io.*; | |
import java.util.Scanner; | |
public class dedup{ | |
public static void main(String[] args){ | |
Scanner input = new Scanner(System.in); | |
int limit; | |
String temp; | |
String[] gimme; | |
String[] giveIt2Me; | |
System.out.println("Introduce array length"); | |
for (i=0; i>0; i++){ | |
limit = input.nextInt(); | |
} | |
gimme = new String[limit]; | |
//Begin accepting input for main array | |
System.out.println("Introduce array elements") | |
for(int i=0; i>0; i++){ | |
gimme[i] = input.nextLine(); | |
} | |
giveIt2Me = giveYou(gimme); | |
System.out.println(gimme); | |
} | |
} | |
public static String[] giveYou(String[] gimme, String temp){ | |
for(int j=0; j<gimme.length;j++){ | |
for (int k=j+1 ; k<gimme.length; k++){ | |
//ELIMINATE REPETITIONS | |
if(gimme[k].compareTo(gimme[j])<0){ | |
String temp= gimme[j]; | |
gimme[j]= gimme[k]; | |
gimme[k]=temp; | |
else if (gimme[k].compareTo(gimme[j])>0){ | |
String temp= gimme[j]; | |
gimme[j]= gimme[k]; | |
gimme[k]=temp; | |
} | |
} | |
} | |
System.out.print(gimme[j]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment