1

If I have n of elements (e.g n=100)

int n=100; 
int[] n=new  int[n];
System.out.print("Enter something:");
Integer input =(Integer) System.console().readLine();

And I divide n to intervals (e.g partitioning=10)

So in this case I have 10 intervals: [0,9],[10,19],[20,29]...[90,100]

The question is:

If user input a element, how to get its interval? I want to know if this number located in first 10 or in second ten or third...

But without using switch or for loop. I want it mathematically, with equations.

agentp
  • 6,849
  • 2
  • 19
  • 37
Hoda Osama
  • 51
  • 1
  • 7
  • Your question seems a bit unclear to me. Please clarify. – Ehsan88 Jan 03 '16 at 07:28
  • i have n of elements for example n=100 , The user will give me number between [0,100] .I want to distribute this number.I want to know if this number located in first 10 or second 10 or third. what is equation? – Hoda Osama Jan 03 '16 at 07:51
  • 1
    You know how to get the interval from its index. (0th is [0*10, 0*10 + (10 - 1)], 1st is [1*10, 1*10 + (10 - 1)], ...) Is not finding the index a simple euclidian division? – Laurent LA RIZZA Jan 03 '16 at 08:24

1 Answers1

1

Just divide the number by 10 using Integer Division and add 1:

bucket number = n / 10 + 1
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928