MODULE - 2 Java
MODULE - 2 Java
JAVA PROGRAMMING
Procedure to find the average of two numbers,
1) Take two numbers
2) Declare a sum variable
3) Calculate the addition of two numbers and assign them to the sum variable
4) Find average as average = sum/2
5) Finally, display the result of the average value
1.Write a Java program to find the average of two numbers.?
• First, we will develop a simple Java program by hardcoding the values
i.e. required values will be initialized inside the program.
Java program to find average of two numbers
public class Average {
public static void main(String[] args) {
// display result
System.out.println("Average: " + avg );
}
}
Output for the different test-cases:-
Enter two numbers: 50 100
Average: 75.0
Enter two numbers: -100 125
Average: 12.5
TASKS TO BE COMPLETED:
1. Write a program in Java to calculate the average of three subjects and
display total and average marks.?