My issues: 1) I know I'm suppose to loop through each element of fahr[i] & compare each element to get: 1. above avg, 2. equal to avg, 3. below avg, but I a) don't know if my loop is correct b) what to put in the ( ) of System.out.printf(what do I put here?, variable) relevant java code to 1): System.out.println("Above Average:"); int above = 0; //count above avg int below = 0;//count below avg for (i = 0; i < fahr.length; i++) if (fahr[i] > sumF) above++; if (fahr[i] < sumF) below++; } System.out.printf( , above); System.out.println(); System.out.println("Equal to Average:"); System.out.printf( , above); System.out.println("Below Average:"); System.out.printf( , below); System.out.println(); 2) All output needs to be right-justified & aligned by decimal point. I use the sample from https://stackoverflow.com/questions/16629476/how-to-center-a-print-statement-text: String h = "Hello"; System.out.println(String.format("%-20s", h)); } Am I using this format for System.out.printf() & System.out.println(String.format( correctly throughout my method defs? full Java code: import java.util.Scanner; import java.util.Arrays; public class Main { public static void printOutput(double[] fahr, double[] celsius, double[] kelvin) { int i = 0; String title = "Title"; System.out.println(String.format("%-20s", title)); System.out.println(); System.out.println(String.format("%33s%33s%33", "Fahr", "Cels", "Kelv")); System.out.println(); System.out.println(String.format("%33s%33s%33", "======", "======", "======")); System.out.println(); //pass value for 3 temps unit conversions & format them double sumF = 0; double sumC = 0; double sumK = 0; for (i = 0; i < fahr.length; i++) { System.out.printf("%33s%33s%33s", fahr[i], celsius[i], kelvin[i]); sumF += fahr[i]; sumC += celsius[i]; sumK += kelvin[i]; } System.out.println(String.format("%33s%33s%33", "======", "======", "======")); System.out.println("Average:"); //calculate avgs sumF = sumF / fahr.length; sumC = sumC / fahr.length; sumK = sumK / fahr.length; System.out.printf("%33s%33s%33s", sumF, sumC, sumK); System.out.println(); System.out.println("High:"); //calculate max int max = 0; int min = 0; for (i = 0; i < fahr.length; i++) { if (fahr[i] > max) max = fahr[i]; if (celsius[i] > max) max = celsius[i]; if (kelvin[i] > min) max = celsius[i]; } System.out.println(); System.out.printf("%33s%33s%33s", sumF[fahr.length - 1], sumC[celsius - 1], sumK[kelvin - 1]); // in ascending order System.out.println(); System.out.println("Low:"); System.out.format("%33sf%33sf%33s", fahr[0], celsius[0], kelvin[0]); System.out.println(); //count the element of fahr[i] that's above avg, equal to avg, below avg System.out.println("Above Average:"); int above = 0; //if it's above the average, count it int below = 0;//if it's below the average, count it for (i = 0; i < fahr.length; i++)//what do I put in the ( ) of the for loop? if (fahr[i] > sumF) above++; if (fahr[i] < sumF) below++; } System.out.printf( , above);//what do I put as the 1st spaceholder? System.out.println(); System.out.println("Equal to Average:"); System.out.printf( , above); //what do I put as the 1st spaceholder? System.out.println("Below Average:"); //don't know how to calculate below avg System.out.printf( , below); //what do I put as the 1st spaceholder? System.out.println(); //calculate std deviation System.out.println("Standard Deviation:"); /* use https://en.wikipedia.org/wiki/Standard_deviation For a finite set of numbers, the population standard deviation is found by taking the square root of the average of the squared deviations of the values subtracted from their average value. The marks of a class of eight students (that is, a statistical population) are the following eight values: step 1: get the average of fahr[i] step 2: calculate the deviations of each data point from the mean, and square the result of each: Ex. Let's say there was 2 #'s entered for fahr[i[ & the average is 5: (2-5)^2=9 (4-5)^2=1 step 3: The variance is the mean of these values: variance^2= (9+1)/2 =5 step4 : the population standard deviation is equal to the square root of the variance: std dev= sqroot(5) =2.2 */ } } public static void main(String[] args) { // write your code here Scanner scnr = new Scanner(System.in); int i=0; System.out.println("How many temperature numbers do you want to enter? :"); int num=scnr.nextInt(); if(num < 1 || num > 35) { System.out.println("Please enter within the range of 1-35 or this cycle will loop forever"); }else { double fahr[]=new double[num]; double celsius[]=new double[num]; double kelvin[]=new double[num]; while(i 350) System.out.println("Number is out 1-35 range. Please enter again."); else { fahr[i] = temp; i++; } } Arrays.sort(fahr); //Why does fahr[i] give an error? //calculate celsius for (i=0; i
My issues:
1) I know I'm suppose to loop through each element of fahr[i] & compare each element to get: 1. above avg, 2. equal to avg, 3. below avg, but I
a) don't know if my loop is correct
b) what to put in the ( ) of System.out.printf(what do I put here?, variable)
relevant java code to 1):
System.out.println("Above Average:");
int above = 0; //count above avg
int below = 0;//count below avg
for (i = 0; i < fahr.length; i++)
if (fahr[i] > sumF)
above++;
if (fahr[i] < sumF)
below++;
}
System.out.printf( , above);
System.out.println();
System.out.println("Equal to Average:");
System.out.printf( , above);
System.out.println("Below Average:");
System.out.printf( , below);
System.out.println();
2) All output needs to be right-justified & aligned by decimal point. I use the sample from https://stackoverflow.com/questions/16629476/how-to-center-a-print-statement-text:
String h = "Hello"; System.out.println(String.format("%-20s", h)); }
Am I using this format for System.out.printf() & System.out.println(String.format( correctly throughout my method defs?
full Java code:
import java.util.Scanner;
import java.util.Arrays;
public class Main {
public static void printOutput(double[] fahr, double[] celsius, double[] kelvin) {
int i = 0;
String title = "Title";
System.out.println(String.format("%-20s", title));
System.out.println();
System.out.println(String.format("%33s%33s%33", "Fahr", "Cels", "Kelv"));
System.out.println();
System.out.println(String.format("%33s%33s%33", "======", "======", "======"));
System.out.println();
//pass value for 3 temps unit conversions & format them
double sumF = 0;
double sumC = 0;
double sumK = 0;
for (i = 0; i < fahr.length; i++) {
System.out.printf("%33s%33s%33s", fahr[i], celsius[i], kelvin[i]);
sumF += fahr[i];
sumC += celsius[i];
sumK += kelvin[i];
}
System.out.println(String.format("%33s%33s%33", "======", "======", "======"));
System.out.println("Average:");
//calculate avgs
sumF = sumF / fahr.length;
sumC = sumC / fahr.length;
sumK = sumK / fahr.length;
System.out.printf("%33s%33s%33s", sumF, sumC, sumK);
System.out.println();
System.out.println("High:");
//calculate max
int max = 0;
int min = 0;
for (i = 0; i < fahr.length; i++) {
if (fahr[i] > max)
max = fahr[i];
if (celsius[i] > max)
max = celsius[i];
if (kelvin[i] > min)
max = celsius[i];
}
System.out.println();
System.out.printf("%33s%33s%33s", sumF[fahr.length - 1], sumC[celsius - 1], sumK[kelvin - 1]); // in ascending order
System.out.println();
System.out.println("Low:");
System.out.format("%33sf%33sf%33s", fahr[0], celsius[0], kelvin[0]);
System.out.println();
//count the element of fahr[i] that's above avg, equal to avg, below avg
System.out.println("Above Average:");
int above = 0; //if it's above the average, count it
int below = 0;//if it's below the average, count it
for (i = 0; i < fahr.length; i++)//what do I put in the ( ) of the for loop?
if (fahr[i] > sumF)
above++;
if (fahr[i] < sumF)
below++;
}
System.out.printf( , above);//what do I put as the 1st spaceholder?
System.out.println();
System.out.println("Equal to Average:");
System.out.printf( , above); //what do I put as the 1st spaceholder?
System.out.println("Below Average:"); //don't know how to calculate below avg
System.out.printf( , below); //what do I put as the 1st spaceholder?
System.out.println();
//calculate std deviation
System.out.println("Standard Deviation:"); /* use https://en.wikipedia.org/wiki/Standard_deviation
For a finite set of numbers, the population standard deviation is found by taking the square root of the average
of the squared deviations of the values subtracted from their average value. The marks of a class of eight
students (that is, a statistical population) are the following eight values:
step 1: get the average of fahr[i]
step 2: calculate the deviations of each data point from the mean, and square the result of each:
Ex. Let's say there was 2 #'s entered for fahr[i[ & the average is 5:
(2-5)^2=9
(4-5)^2=1
step 3: The variance is the mean of these values:
variance^2= (9+1)/2
=5
step4 : the population standard deviation is equal to the square root of the variance:
std dev= sqroot(5)
=2.2
*/
}
}
public static void main(String[] args) {
// write your code here
Scanner scnr = new Scanner(System.in);
int i=0;
System.out.println("How many temperature numbers do you want to enter? :");
int num=scnr.nextInt();
if(num < 1 || num > 35)
{
System.out.println("Please enter within the range of 1-35 or this cycle will loop forever");
}else {
double fahr[]=new double[num];
double celsius[]=new double[num];
double kelvin[]=new double[num];
while(i<num)
{
System.out.println("Enter "+(i+1)+" fahrenheit temp");
double temp=scnr.nextDouble();
if(temp < -150 || temp > 350)
System.out.println("Number is out 1-35 range. Please enter again.");
else {
fahr[i] = temp;
i++;
}
}
Arrays.sort(fahr); //Why does fahr[i] give an error?
//calculate celsius
for (i=0; i<num;i++) {
double temp=fahr[i];
celsius[i] = (temp - 32)/1.8;
}
//calculate Kelvin
for (i=0; i<num;i++) {
double temp = fahr[i];
kelvin[i] = (temp - 32) / 1.8 + 273.15;
}
printOutput(fahr, celsius, kelvin);
}
}
}
![Title
Fahren
Celsius
Kelvin
10.0
-10.0
5.0
20.0
20.0
10.0
30.0
30.0
40.0
Average:
20.0
14.0
20.0
Equal to Average:](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fc14768d3-3359-407d-85b4-624ecac227c9%2Ffc43adb7-2210-47cb-bb25-a001ef07cba2%2Fmhl4b3c_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Concepts of Database Management](https://www.bartleby.com/isbn_cover_images/9781337093422/9781337093422_smallCoverImage.gif)
![Prelude to Programming](https://www.bartleby.com/isbn_cover_images/9780133750423/9780133750423_smallCoverImage.jpg)
![Sc Business Data Communications and Networking, T…](https://www.bartleby.com/isbn_cover_images/9781119368830/9781119368830_smallCoverImage.gif)