Reputation: 71
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.
Upvotes: 1
Views: 139
Reputation: 1039378
Just divide the number by 10 using Integer Division
and add 1:
bucket number = n / 10 + 1
Upvotes: 1