This are my requirements:
- Read in an integer from the user (n)
- Declare an array of floating point numbers of size n
- Fill in this array with random floating point numbers between 0 and 100.
- Calculate and display the percentage of values in the array that are at least 70
I dont know how to do the last part.
import java.util.Random;
import java.util.Scanner;
/**
*
*
*/
public class Mo {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
System.out.print("please enter a number: ");
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
float[] values;
values = new float[n];
int[] counters;
counters = new int[n];
Random r = new Random();
for(int i=0; i < values.length; i++)
{
values[i] = r.nextInt(100);
System.out.print(values[i] + " " );
}
System.out.println();
}
}
Count numbers of values that are <70 then divide this count by total count
if (values[i] >= 70 )
count++;
outside the for
count/values.length*100