We need you!

We're working hard on the next version of Developer Fusion. Let us know what you think we should be up to!

Members

Technology Zones

Articles

Hosted By

MaximumASP

Info

help me in my project,about array

Last post 03-27-2008 12:36 PM by jmobile. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 03-08-2008 1:40 PM

    • xaimei
    • Not Ranked
    • Joined on 03-08-2008
    • Philippines
    • New Member
    • Points 45

    help me in my project,about array

    how will i do this one:

    Create a program that will

                       1. allow user to input 5 numbers using array.

                       2. Determine if the list is UNIQUE or NOT UNIQUE

    NOTE: UNIQUE - if there are no similar elements in the list

               NOT-UNIQUE - if there are similar elements in the list

     

    EXAMPLE:

    1        2        3          4         4

    It's NOT UNIQUE!

     

     

    please help me..
     

    • Post Points: 10
  • 03-27-2008 12:36 PM In reply to

    • jmobile
    • Not Ranked
    • Joined on 03-27-2008
    • South Africa
    • New Member
    • Points 5

    Re: help me in my project,about array

    hi,

    Let me know if this solves your problem....

     

    Please read comment carefully..\

     

    /*
    Author: Agbebiyi Babajide
    Location: South Africa
    Schoo;: Tswhane University of Technology
    E-mail: jydeshow@gmail.com, Agbebiyib@hotmail.com
    Dept: ICT/ Enterprise Applications Development
    Remark: This very simple program is to check wether an array
    element repeats it self.
    This code can be reused as long as the comment is not changed or altered..
    */
    public class ArrayDemo{
     
     // check to see if its unique or not
     boolean type;
     
     public static void main (String[] Agbebiyi){
      
      // from static to non static, SAME as==================
      
         // ArrayDemo ad= new ArrayDemo();  
      //   ad.startApp();
      
      new ArrayDemo().startApp();
     }
     
     
     public void startApp(){
      
      int [] numbers={2,3,4,5,6,7,8,9,0,11,12};
      
      // initalize array, can also get values from JOptionPane or scanner
      
      // Outer loop
      for(int x=0; x<numbers.length;x++){  
       
       // inner loop, this will go through all elements from 0 to last.
       // this loop is controlled by the outer loop
       for(int y=0; y<numbers.length;y++ ){
        
         if(numbers[x]==numbers[y++]){
        
          type=true;
              
                }
       
                  else
               {
          type=false;
              
               }   
          }
       
      }
       
      
      //print ur output
      System.out.println("Array is "+ type);
      
      
      
     }
     
    }// end of class

     

     

     

     

    • Post Points: 5
Page 1 of 1 (2 items)