If i have an array $string = array(1,2,6,2,9,6,7,3,1,2); How
can i get only unique values from it?
Array
(
[0] => 1
[1] => 2
[2] => 6
[4] => 9
[6] => 7
[7] => 3
)

Answer Posted / sreejesh1987

import java.io.*;
class Unique
{
public static void main(String args[])
{
int i,n;
int [] $string=new int[20];
DataInputStream ds=new DataInputStream(System.in);

try
{
System.out.println("Enter the number of elements:");
n=Integer.parseInt(ds.readLine());


System.out.println("Enter the numbers");
for(i=0;i<n;i++)
$string[i]=Integer.parseInt(ds.readLine());

for(i=0;i<n;i++)
{
int f=0;
for(int j=0;j<i;j++)
if($string[j]==$string[i])
f=1;
if(f==0)
System.out.print("$string["+i+"]:"+$string[i]+"\n");
}
}

catch(Exception e){}


System.exit(0);
}
}

Is This Answer Correct ?    1 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the best way to make wordpress plugin

2840


can we pass variable in array to traverse it?

2128


How can export database using php code?

1718


What is used of serialize and unserialize in php?

2727


Given a string=”me,I,myself”; .Using javascript only create an array out of this string and then send a POST request to the url “record.php” without reloading the page. The post key parameters should be n1,n2 and n3 respectively.

2487






What is 301 redirects in php? When are we used 301 redirects in our projects?

2131


Given a string=”me,I,myself”; .Using javascript only create an array out of this string and then send a POST request to the url “record.php” without reloading the page. The post key parameters should be n1,n2 and n3 respectively.

2757


Which framework is best in php among Smarty, Cakephp, Joomla, Drupal, Zend or Something else...? If any then Why?

8356


Is there any way to open notepad within php?

1834


How can restrict user to type upto 8 characters in textbox in php?

1697


How can call any javascript function without saying onclick, onchange, onblur etc events in php?

4333


what is main difference between array_push and array_pop?

3885


How can manage theme in php?

2171


Which keyword is alias for count keyword in php?

1814


How can i know that how many user are visited to my page in php?

1766