Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The peaks are at x[1] = 0.5, x[10] = 0.7, x[12] = 0.45, x[15] = 0.85, x[17] = 0.

ID: 674519 • Letter: T

Question

The peaks are at x[1] = 0.5, x[10] = 0.7, x[12] = 0.45, x[15] = 0.85, x[17] = 0.65.

For this project, you will write a java program that scans through an array of data, finds the peaks based on the criterion defined above, and sorts them into non­descending order. Here’s what you program should do:

Declare and initialize an array x[] of 20 floats.
float [] x = {0.2f, 0.5f, 0.1f, 0.15f, 0.2f, 0.13f, 0.3f, 0.25f, 0.3f, 0.3f,

0.7f, 0.2f, 0.45f, 0.15f, 0.2f, 0.85f, 0.3f, 0.65f, 0.2f, 0.1f};

Print the elements of x[], 10 on each line.
Then locate the peaks in x[], place them in an array peaks[] Print the index and data for each peak, in the sorted order

Explanation / Answer

class peaks
{
public static void main(String args[])
{
float x[] = {0.2f, 0.5f, 0.1f, 0.15f, 0.2f, 0.13f, 0.3f, 0.25f, 0.3f, 0.3f,
0.7f, 0.2f, 0.45f, 0.15f, 0.2f, 0.85f, 0.3f, 0.65f, 0.2f, 0.1f};
for(int i=0;i<20;i++)
System.out.println("element "+i+" : "+x[i]);
float peaks[]=new float[10];
int temp=0;
for(int i=0;i<20;i++)
{
if(x[i]==0.5f)
{
System.out.println("peak "+temp+" is : "+x[i]);
peaks[temp]=x[i];
temp++;
}
if(x[i]== 0.7f)
{
System.out.println("peak "+temp+" is : "+x[i]);
peaks[temp]=x[i];
temp++;
}if(x[i]==0.45f)
{
System.out.println("peak "+temp+" is : "+x[i]);
peaks[temp]=x[i];
temp++;
}if(x[i]==0.85f)
{
System.out.println("peak "+temp+" is : "+x[i]);
peaks[temp]=x[i];
temp++;
}if(x[i]==0.65f)
{
System.out.println("peak "+temp+" is : "+x[i]);
peaks[temp]=x[i];
temp++;
}
}
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote