Answer:
Program in Java:
import java.util.Scanner;
import java.lang.Math;
public class MyClass {
public static void main(String args[]) {
Scanner input = new Scanner(System.in);
float f0; double r=0.0;
System.out.print("Initial Key Frequency: ");
f0 = input.nextFloat();
int numkey = 1;
System.out.print(f0+" ");
r= Math.pow(2,(1.0/12.0));
while(numkey<=4){
f0*=r;
System.out.print(f0+ " ");
numkey++;
}
}
}
Explanation:
This line declares f0 as float and r as double. f0 represents the initial key frequency
float f0; double r=0.0;
This line prompts the user for initial key frequency
System.out.print("Initial Key Frequency: ");
This line gets the initial key frequency from the user
f0 = input.nextFloat();
This declares numkey as integer and also initializes it to 1
int numkey = 1;
This prints the initial key
System.out.print(f0+" ");
This calculates r
r= Math.pow(2,(1.0/12.0));
The following iteration calculates and prints the next 4 key frequencies
while(numkey<=4){
f0*=r;
System.out.print(f0+ " ");
numkey++;
}
}
}