fork download
  1. import java.util.Scanner;
  2. class CalculateAverage {
  3.  
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6.  
  7. System.out.print("Enter the first number: ");
  8. int num1 = scanner.nextInt();
  9.  
  10. System.out.print("Enter the second number: ");
  11. int num2 = scanner.nextInt();
  12.  
  13. // Calculate the average
  14. double average = (double) (num1 + num2) / 2;
  15.  
  16. System.out.println("The average of " + num1 + " and " + num2 + " is: " + average);
  17.  
  18. scanner.close();
  19. }
  20. }
Success #stdin #stdout 0.26s 60976KB
stdin
4 5
stdout
Enter the first number: Enter the second number: The average of 4 and 5 is: 4.5