In: Computer Science
So, I'm trying to get an average revolutions/minute from an input vector.
Here's a sample vector:
V=[10200 11000 11800 12300 13100 13900 14400 15020 15850 16250]
The units are in ms so 10200 is 10.2 seconds.
The revolutions is between every successive value. So 11000 - 10200 is 1 revolutions per 800 ms and et cetera.
I need help figuring out a code that will allow me find the average cadence from the whole dataset.
Thank you in advance
Program :-
import java.util.Scanner;
public class VectorQ {
public static void main(String[] args) {
Scanner scan = new
Scanner(System.in);
System.out.print("Enter number of
sample vector data : ");
int data = scan.nextInt();
int i;
float timeSum = 0f;
int revolution =0;
float result;
System.out.println("Enter sample
vector data : ");
int[] v = new int[data];
for(i=0; i<data; i++)
{
v[i] =
scan.nextInt();
}
for(i=1; i<data; i++)
{
timeSum += (v[i]
- v[i-1]);
revolution++;
}
timeSum = (timeSum/1000f);
result = (revolution/timeSum) *
60;
System.out.println("average rate =
" + (int)result + " revolution/minute");
scan.close();
}
}