Question: 1. Write a java program that asks the user for two integer numbers. The program should calculate the average of the numbers. For example, if

1.

Write a java program that asks the user for two integer numbers. The program should calculate the average of the numbers. For example, if the user enters 2 (first number) and 3 (second number), the result is 2.5. You must create a method that receives two numbers from the main method and returns the average to the caller.

Possible program structure and its functions:

1) main method

Ask user for integer numbers Call a method and pass the two numbers. Receive the result from the method. Print the result.

2) a method

Receive two numbers from main method. Calculate the average of the numbers Return the average to the caller. ** do not print anything in this method.

REQUIREMENT: Data type of the input numbers must be int and the average must be double. You must use the concept of 'type casting' when calculating the average.

Example Log

input 1st number : 2 input 2nd number : 3 Average = 2.5

2.

Write a java program that asks the user for two integer numbers. The program should calculate the sum of all the integer numbers from the first number up to the second number. For example, if the user enters 5 (first number) and 10 (second number), the result is 45 (= 5+6+7+8+9+10). You must create a method that receives two numbers from the main method and returns the sum to the caller. Assume the first number is less than the second number.

Possible program structure and its functions:

1) main method

Ask user for integer numbers Call a method and pass the two numbers. Receive the result from the method. Print the result.

2) a method

Receive the two numbers from main method. Calculate the sum of all the numbers from the first number up to the second number Return sum to the caller. ** do not print anything in this method.

Example Log

input 1st number : 5 input 2nd number : 10 sum = 45


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!