Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Still Need Help with this String Problem

807569Oct 1 2006 — edited Oct 1 2006
basically, i need to create a program where I input 5 words and then the program outputs the number of unique words and the words themselves. for example, if i input the word hello 5 times, then the output is 1 unique word and the word "hello". i have been agonizing over this dumb problem for days, i know how to do it using hashmap, but this is an introductory course and we cannot use more complex java functions, does ANYONE know how to do this just using arrays, strings, for loops, if clauses, etc. really basic java stuff. i want the code to be able to do what the following program does:
import java.io.*; import java.util.ArrayList; 
    public class MoreUnique { 
       public static void main(String[] args) throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String str[] = new String[5]; int uniqueEntries = 0; ArrayList<String> ue = new ArrayList<String>(); 
         for (int i = 0; i < 5; i++) { System.out.print((i +1) + ": "); str[i] = br.readLine(); } 
         for (int j = 0; j < 5; j++) { 
            if (!ue.contains(str[j].toLowerCase())) { ue.add(str[j].toLowerCase()); } } uniqueEntries = ue.size(); System.out.print("Number of unique entries: " + uniqueEntries + " { "); 
         for (int q = 0; q < ue.size(); q++ ) { System.out.print(ue.get(q) + " "); } System.out.println("}"); } } 
but i need to find how to do it so all 5 words are put in at once on one line, and without all the advanced java functions that are in here, can anyone help out?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 29 2006
Added on Oct 1 2006
15 comments
263 views