• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Arrays

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello, i need helps. I learn arrays and i need the is to extract the duplicates from  arrays  and show how many times the duplicate number is repeated.

                 
I missed something and I need a little help.How to solve this problem, i need one more varibale to set ?
Thanks
       
 
Saloon Keeper
Posts: 9729
80
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When posting code always UseCodeTags (<--link). I fixed it for you this time.

Welcome to the Ranch.
 
Bartender
Posts: 387
47
Firefox Browser MySQL Database Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello, welcome to Coderanch!

It seems some of your code is missing; the loops don't have closing brackets. What in particular can we help you with? Do you get errors when you try to compile your code?
 
Mario Mariofil
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jj Roberts wrote:Hello, welcome to Coderanch!

It seems some of your code is missing; the loops don't have closing brackets. What in particular can we help you with? Do you get errors when you try to compile your code?


i was put brackets here, i have in code brackets

int [] arr = { 4, 12,1,0,0,12,4};




outuput is :
4 is 1  repeated times.
12 is 1 repeated times.
 0 is 1 repeated times.

some of code mising, im trying to understand this, but i need help
 
Jesse Duncan
Bartender
Posts: 387
47
Firefox Browser MySQL Database Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are trying to find the duplicate numbers in the array. 0, 4, and 12 are repeated in the array. You are getting output for the right numbers. What is missing? What do you want it to do? I did notice, though that if there is more then two of one number, the program will not work correctly.
 
Mario Mariofil
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jj Roberts wrote:You are trying to find the duplicate numbers in the array. 0, 4, and 12 are repeated in the array. You are getting output for the right numbers. What is missing? What do you want it to do?



Yes i was trying to find dupilcate in array, and after that i was think to print  number of duplicate element array. That numbers are duplicate and they are x times repeated.
In this example 0 ,4, 12 are 2 time repated. What i missed ?
Thank you
 
Jesse Duncan
Bartender
Posts: 387
47
Firefox Browser MySQL Database Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ah, I see. The problem is that you are only counting every time you find two of the same numbers, you are not counting how many there are of that number. Unfortunately I don't think the approach you are using at the moment will give you what you want. I suggest you start by counting how many there are of each number. Could you write some code to do that?
 
Mario Mariofil
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jj Roberts wrote:Ah, I see. The problem is that you are only counting every time you find two of the same numbers, you are not counting how many there are of that number. Unfortunately I don't think the approach you are using at the moment will give you what you want. I suggest you start by counting how many there are of each number. Could you write some code to do that?



yes i can write that code. and that way it would solve this problem that I want to solve, after that i  can make condition. right ?
 
Jesse Duncan
Bartender
Posts: 387
47
Firefox Browser MySQL Database Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If I am understanding you right, yes. Post your code to count how many of each number first, though, and we can take it from there.
 
Jesse Duncan
Bartender
Posts: 387
47
Firefox Browser MySQL Database Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you're stuck here's a hint: you should look at using a map.
 
Onion rings are vegetable donuts. Taste this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic