• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Java programming.

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Question -

You are given an array a with N integers and an integer K. Output the smallest number in array which occurs exactly K times in an array. There will always be a number that is occurring K times.


Sample Input
5
2 2 1 3 1
2

Sample Output
1

MY code -

why does my code says runtime error?
 
Rancher
Posts: 664
10
Android Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please post the full stacktrace
 
Bartender
Posts: 390
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
Welcome to the Ranch!

I formatted your code for you. Doesn't that make it much easier to see what is going on?
 
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome again

Please always put spaces between (non‑unary) operators and operands: not for (i=0; i<N; i++) ... please but for (i = 0; i < N; i++) ... No space in i++ however. Don't put constants in the for header. Write myArray.length instead. >
I like your counting technique, but what makes you think there will not bemore than ten different values?
 
reply
    Bookmark Topic Watch Topic
  • New Topic