• Post Reply Bookmark Topic Watch Topic
  • New Topic

need java programs anyone post here  RSS feed

 
Will Zelan
Ranch Hand
Posts: 56
Flex Python Windows Vista
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1)comparing two arrays and remove duplicates from original array?
2.remove duplicate elements from array without using collections?
3)2,10,15,2 add the elements in command line argument and remove duplicates?
4)Given two arrays, 1,2,3,4,5 and 2,3,1,0,5 find which number is not present in the second array.
5)How do you find second highest number in an integer array?

 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This site is NotACodeMill(←click). You are expected to ShowSomeEffort(←click) and DoYourOwnHomework(←click).

If you do that, you'll get plenty of help.
 
Will Zelan
Ranch Hand
Posts: 56
Flex Python Windows Vista
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1)comparing two arrays and remove duplicates in java
k if we assingning two arrays
int array1[]={5,2,3,7};
int array2[]={5,1,2,6,7};
so i just initialize the two array with duplicate values
so how to compare them and remove duplicates how to implement them any ideas
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Will Zelan wrote:1)comparing two arrays and remove duplicates in java
k if we assingning two arrays
int array1[]={5,2,3,7};
int array2[]={5,1,2,6,7};
so i just initialize the two array with duplicate values
so how to compare them and remove duplicates how to implement them any ideas

What have you tried? Do you know how to compare ints? Do you know how to access a single int that resides in the array?
 
fred rosenberger
lowercase baba
Bartender
Posts: 12563
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The first step on any program is to turn off the computer. Get out some paper and pencils, and start playing around with how YOU would do it.

Then, start writing out the steps, as if you were explaining to a 10 year old child how THEY should do it. Go back and refine the steps, making them simpler and more granular. Revise it several times. Write it out in English, not java (or any other programming language).

THEN - and ONLY then - should you start writing any code.
 
Will Zelan
Ranch Hand
Posts: 56
Flex Python Windows Vista
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Steve Luke wrote:
Will Zelan wrote:1)comparing two arrays and remove duplicates in java
k if we assingning two arrays
int array1[]={5,2,3,7};
int array2[]={5,1,2,6,7};
so i just initialize the two array with duplicate values
so how to compare them and remove duplicates how to implement them any ideas

What have you tried? Do you know how to compare ints? Do you know how to access a single int that resides in the array?

whats wrong in declaring above code that is int array1[]={5,2,3,7};
oh hold on
we can int a[]=new int[5];
for(int i=0;i<5;i++)
{a[i]=integer.parseInt(br.readLine());
}
 
Will Zelan
Ranch Hand
Posts: 56
Flex Python Windows Vista
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
anyone tell me whats the wrong declaring array which i have been post above
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Will Zelan wrote:anyone tell me whats the wrong declaring array which i have been post above


Post real code--an SSCCE(←click), and copy/paste the exact, complete error message.
 
Will Zelan
Ranch Hand
Posts: 56
Flex Python Windows Vista
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeff Verdegan wrote:
Will Zelan wrote:anyone tell me whats the wrong declaring array which i have been post above


Post real code--an SSCCE(←click), and copy/paste the exact, complete error message.

what s the link i didnt understand,i am looking for comparing two arrays and remove duplicates, so i declared two arrays with above post but some one saying its wrong to declare arrray in that manner, but whats the wrong with the type of declaring array
 
Campbell Ritchie
Marshal
Posts: 56527
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Will Zelan wrote: . . . but some one saying its wrong to declare arrray in that manner, . . .
Nobody has said that.
 
Will Zelan
Ranch Hand
Posts: 56
Flex Python Windows Vista
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:
Will Zelan wrote: . . . but some one saying its wrong to declare arrray in that manner, . . .
Nobody has said that.

oh k ,i declare 2 types of arrays with duplicate values ,now how to compare and remove duplicate give me some idea about that i will try it
 
Campbell Ritchie
Marshal
Posts: 56527
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Draw it on a piece of paper; once you have done that it will be easy to convert it to code.
 
Will Zelan
Ranch Hand
Posts: 56
Flex Python Windows Vista
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i can able to compare the two arrays but i dnt have an idea how to remove duplicates in one array without using collections, any one give a logic i will implement
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Will Zelan wrote:i can able to compare the two arrays but i dnt have an idea how to remove duplicates in one array without using collections

There is a key feature of the array which makes what you want to do difficult. Can you describe what an array is, and why that makes doing what you say above hard?

In the end, you will have to come up with a definition of what it means to 'remove duplicates' - what do you want to do with the non-duplicates. and what 'remove' actually means. But to understand that stuff you have to understand what an array is, by definition in Java, first.
 
Will Zelan
Ranch Hand
Posts: 56
Flex Python Windows Vista
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Steve Luke wrote:
Will Zelan wrote:i can able to compare the two arrays but i dnt have an idea how to remove duplicates in one array without using collections

There is a key feature of the array which makes what you want to do difficult. Can you describe what an array is, and why that makes doing what you say above hard?

In the end, you will have to come up with a definition of what it means to 'remove duplicates' - what do you want to do with the non-duplicates. and what 'remove' actually means. But to understand that stuff you have to understand what an array is, by definition in Java, first.

array is nothing but more than one value can be stored,we can store the values in index based and we can retrieve the number by using for loop,then we will print the values ok,
in my program two arrays are there a and b which having numbers with duplicate values(same values present in the another arrray) i want to compare both arrays and remove duplicates and print both a and b.iam beginner in java,so i just have an idea to compare both arrays a and b ,but i dont know how to remove duplicates so if you have know about that or know about logic tell me
for example a array contains 5,4,2,3,1 and b array contains 5,4,8,9,7,so output will be a is 5 4 2 3 1 and b is 8 9 7
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Will Zelan wrote:array is nothing but more than one value can be stored,we can store the values in index based and we can retrieve the number by using for loop,then we will print the values

That is a very incomplete 'definition' of an array focused more on how it is used rather than what it is. If you read this Tutorial page you should get an idea of what an Array is. And if you read the first paragraph close enough you should understand why you need to define what you mean by 'remove duplicates' and what you expect the results to be.
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just to point out why I am dwelling on this: You said:
for example a array contains 5,4,2,3,1 and b array contains 5,4,8,9,7,so output will be a is 5 4 2 3 1 and b is 8 9 7

That result is impossible to achieve. If you understand arrays you should understand why. You might also might come up with a suitable re-statement of the expected results so as to provide an achievable outcome.
 
Will Zelan
Ranch Hand
Posts: 56
Flex Python Windows Vista
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Steve Luke wrote:Just to point out why I am dwelling on this: You said:
for example a array contains 5,4,2,3,1 and b array contains 5,4,8,9,7,so output will be a is 5 4 2 3 1 and b is 8 9 7

That result is impossible to achieve. If you understand arrays you should understand why. You might also might come up with a suitable re-statement of the expected results so as to provide an achievable outcome.

mistake is mine,i understand what is array?array is fixed that is we cannot able to increase or decrease,so above program is impossible,
,is it ok
 
Will Zelan
Ranch Hand
Posts: 56
Flex Python Windows Vista
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why there is no reply for this thread anyprobs
 
Campbell Ritchie
Marshal
Posts: 56527
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because there is nothing else to say at the moment.
 
Will Zelan
Ranch Hand
Posts: 56
Flex Python Windows Vista
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Because there is nothing else to say at the moment.

what does it means?iam just asking to know is it possible for the program and some instruction ,logics and ideas only to develop myself from You all
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!