beginner


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: beginner

Hybrid View

  1. #1
    Join Date
    Jul 2011
    Posts
    1

    beginner

    Hi!
    I am very young and very inquisitive!
    I the beginning programmer.
    My program
    (Sorting alphabetically)
    input file:
    ccc
    ddd
    bbb
    ddd
    aaa

    output file:
    aaa
    bbb
    ccc
    ddd
    ddd


    How to make so that in a target file there were no repetitions?
    that was like this:
    aaa
    bbb
    ccc
    ddd


    Help please!)
    Code:
     
    class Customer implements Comparable<Customer> {
      
    	private String sequance;
       
       public Customer() {
    	   sequance = "ppp";
    	     }
       
       public Customer(String string) {
       }
     
       public Customer(String N, String S) {
          this();
          sequance = N;
       }
     
       public String getName() {
          return sequance;
       }
     
       public void setName(String letters) {
          this.sequance = letters;
       }
     
      
     
       public void print() {
          System.out.println(sequance + "\t"  );
       }
     
       @Override
       public int compareTo(Customer o) {
          return this.sequance.compareTo(o.sequance);
       }
     
    }
     
    public class Main {
       public static void main(String[] args) {
          Customer[] cust = new Customer[10];
          String name[] = { "ccc", "ddd", "bbb", "ddd", "aaa", "Alex",
                "Andrej", "Oleg", "Ivan", "Egor" };
          int i;
     
          System.out.println("All customers:");
     
          for (i = 0; i < cust.length; i++) {
             cust[i] = new Customer();
             cust[i].setName(name[i]);
             cust[i].print();
          }
     
    System.out.println("Sorted alphabetically: ");
    char alph[]={'a', 'b', 'c', 'd', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};  
     
        for (int x=0; x<alph.length; x++)
        {for (i=0; i<cust.length; i++)
        {
    if (cust[i].getName().charAt(0)==alph[x])   
    cust[i].print();
        }
      }
     
       }
    }

  2. #2
    Join Date
    Jul 2005
    Location
    SW MO, USA
    Posts
    299
    How to make so that in a target file there were no repetitions?
    Walk thru the list of elements comparing two adjacent elements, if they are equal, remove one of them.

Similar Threads

  1. Beginner Help
    By Moshntsane in forum .NET
    Replies: 1
    Last Post: 03-05-2007, 03:08 PM
  2. working on ASP as a beginner!
    By sahar in forum ASP.NET
    Replies: 2
    Last Post: 12-10-2000, 07:18 PM
  3. Re: (Thanks)New Beginner Tutorials
    By FlSteve in forum vb.announcements
    Replies: 1
    Last Post: 09-14-2000, 03:49 PM
  4. New Beginner Tutorials
    By Burt Abreu in forum vb.announcements
    Replies: 0
    Last Post: 09-08-2000, 03:29 AM
  5. New Beginner Tutorials
    By Burt Abreu in forum vb.announcements
    Replies: 0
    Last Post: 07-26-2000, 01:48 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center