Question: convert the following java code to swift import java.util.Scanner; public class ArrayOfTemperatures2 { public static void main (String [] args) { Scanner keyboard = new

convert the following java code to swift

import java.util.Scanner;

public class ArrayOfTemperatures2 {

public static void main (String [] args)

{

Scanner keyboard = new Scanner (System.in);

System.out.println ("How many temperatures do you have?");

int size = keyboard.nextInt ();

double [] temperature = new double [size];

// Read temperatures and compute their average:

System.out.println ("Enter " + temperature.length + " temperatures:");

double sum = 0;

for (int index = 0 ; index < temperature.length ; index++)

{

temperature [index] = keyboard.nextDouble ();

sum = sum + temperature [index];

}

keyboard.close();

double average = sum / temperature.length;

System.out.println ("The average temperature is " + average);

// Display each temperature and its relation to the average:

System.out.println ("The temperatures are");

for (int index = 0 ; index < temperature.length ; index++)

{

if (temperature [index] < average)

System.out.println (temperature [index] + " below average.");

else if (temperature [index] > average)

System.out.println (temperature [index] + " above average.");

else //temperature[index] == average

System.out.println (temperature [index] + " the average.");

}

System.out.println ("Have a nice week.");

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!