akmalrashd / SC025-Matrix

From & For Matriculations Physical / Computer Science Students
0 stars 0 forks source link

Question 1 - Array - SC025 #4

Open akmalrashd opened 1 year ago

akmalrashd commented 1 year ago

Given a list of daily temperatures for a certain number of days, design an algorithm to determine the maximum temperature. The first input is the number of days.

akmalrashd commented 1 year ago
import java.util.Scanner;
public class Day33
{
    public static void main (String [] args)
    {
        Scanner akmal = new Scanner(System.in);

        System.out.print("Enter number of Days : ");
        int tDays = akmal.nextInt();

        double temperature [] = new double [tDays];
        double maxTemp = -100;
        for ( int i= 0 ; i < tDays ; i++)
        {
            System.out.print( "Enter Temperature of day "+ (i+1) + " (Celcius) : ");
            temperature [i] = akmal.nextDouble();

            if (temperature [i] > maxTemp)
            maxTemp = temperature[i];

        }
        System.out .print("Maxi mum Temperature in "+ tDays + " Days (Celcius) : " + maxTemp);
    }

}