Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

import java.util.Scanner; public class JLynch { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System .

import java.util.Scanner;
public class JLynch {
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
String[] cities = new String[4];
int[] snowfalls = new int[4];
double totalSnowfall =0;
double avgsnowfall;
// Input city names and snowfall amounts
for (int i =0; i <4; i++){
System.out.println("Enter city name: ");
cities[i]= scanner.nextLine();
System.out.println("Enter snowfall amount (in inches) for "+ cities[i]+": ");
snowfalls[i]= scanner.nextInt();
scanner.nextLine(); // to handle the newline character
}
// Display city names and snowfall amounts
System.out.println("
Snowfall amounts:");
for (int i =0; i <4; i++){
System.out.println(cities[i]+": "+ snowfalls[i]+" inches");
totalSnowfall += snowfalls[i];
}
// Compute the average snowfall
avgsnowfall = totalSnowfall/4;
System.out.println("Total Snowfall "+ totalSnowfall +" inches");
System.out.println("Average Snowfall "+ avgsnowfall +" inches");
}
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions