Question
JAVA PROGRAMMING Need help writing Java application. Write a Java application that reads three integers from the user using a Scanner. Then, create functions to
JAVA PROGRAMMING Need help writing Java application.
Write a Java application that reads three integers from the user using a Scanner.
Then, create functions to calculate the sum, product and average of the numbers,
and displays them from main.
(Use each functions' 'return' to return their respective values.) Use the
following sample code as a guide.
Below is a sample code:
import java.util.Scanner;
/**
* Write a Java application that reads three integers from the user using a Scanner.
* Then, create functions to calculate the sum, product and average of the numbers,
and displays them from main.
* (Use each functions' 'return' to return their respective values.) Use the
following sample code as a guide.
*/
public class assignment1_main
{
public static void main(String[] args)
{
int num1, num2, num3;
double sum, product, average;
// Use Scanner class to read the three integer
sum = sum(num1, num2, num3); //The sum method calculates the sum
//Create and call product method to calculate the product
//Create and call average method to calculate the average
System.out.printf("Sum: %f", sum);
// Next print the product and average using similar printf calls.
}//end main
/**
* This method calculates the sum of 3 integers
* @param x the first integer
* @param y the second integer
* @param z the third integer
* @return the sum of the 3 integers
*/
public static double sum(int x, int y, int z)
{
return x + y + z;
}//end sum
}//end class
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started