Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Convert from C# to Java Scanner: using System; public class Rainfall { public static void Main ( ) { / / declare variable and array

Convert from C# to Java Scanner:
using System;
public class Rainfall
{
public static void Main()
{
//declare variable and array
int choice =0;
double[] rainfall = new double[12];
for (int x =0; x <12; ++x)
rainfall[x]=0.0;
for (int x =0; x <12; x +=1)
{//get rainfall amounts
Console.Write("Enter rainfall for month {0}",(x +1));
Console.Write(": ");
rainfall[x]= Convert.ToDouble(Console.ReadLine());
}//end for
do
{//display menu and get menu choice
Console.WriteLine();
Console.WriteLine("1 Display monthly amounts");
Console.WriteLine("2 Display total amount");
Console.WriteLine("3 End program");
Console.Write("Enter your choice: ");
choice = Convert.ToInt32(Console.ReadLine());
//call appropriate function or end program
if (choice ==1)
displayMonthly(rainfall);
else if (choice ==2)
displayTotal(rainfall);
//end ifs
} while (choice ==1|| choice ==2);
}
//function definitions
public static void displayMonthly(double[] rain)
{
Console.WriteLine("Monthly rainfall amounts:");
for (int x =0; x <12; x +=1)
Console.WriteLine(rain[x]);
//end for
}//end of displayMonthly function
public static void displayTotal(double[] rain)
{
double total =0.0;
for (int x =0; x <12; x +=1)
total = total + rain[x];
//end for
Console.WriteLine("Total rainfall: {0}", total);
}//end of displayTotal function
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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

Recommended Textbook for

Database Concepts

Authors: David Kroenke, David Auer, Scott Vandenberg, Robert Yoder

8th Edition

013460153X, 978-0134601533

More Books

Students also viewed these Databases questions