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

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

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