Java.Write the body for the integer method called daysOfFreezing, given the head
ID: 3842872 • Letter: J
Question
Java.Write the body for the integer method called daysOfFreezing, given the header and the call in main shown below. Use the constant FREEZING in your code.
public class ColdOnes {
const int FREEZING = 32;
public static void main(String args[]) {
Scanner stdin = new Scanner(System.in);
int temperature[31];
System.out.print("Enter the low temperature for 31 days: ");
for (int i=0; i < 31; i++) {
temperature[i] = stdin.nextInt();
}
System.out.println("Days below freezing: " +daysOfFreezing(temperature));
}
public static int daysOfFreezing(int farenheit[]) {
// write this method body
}
}
Explanation / Answer
ColdOnes.java
import java.util.Scanner;
public class ColdOnes {
final static int FREEZING = 32;
public static void main(String args[]) {
Scanner stdin = new Scanner(System.in);
int temperature[] = new int[31];
System.out.print("Enter the low temperature for 31 days: ");
for (int i=0; i < 31; i++) {
temperature[i] = stdin.nextInt();
}
System.out.println("Days below freezing: " +daysOfFreezing(temperature));
}
public static int daysOfFreezing(int farenheit[]) {
// write this method body
int days = 0;
for(int i=0;i<farenheit.length;i++){
if(farenheit[i] < FREEZING){
days++;
}
}
return days;
}
}
Output:
Enter the low temperature for 31 days: 1 2 3 4 5 6 7 8 9 10
11 12 13 144 45 56 67 78 88 77 66 55
99 17 18 19 20 21 35 36
67 78
Days below freezing: 18
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.