Computer Science, asked by Anonymous, 3 months ago


Question-4
Write a program in Java to print the sum and average of any two variables by taking the input of the values​

Answers

Answered by Brailest123
2

Answer:

// Find sum and average of two numbers in Java

import java.util.*;

public class Numbers {

public static void main(String args[]) {

int a, b, sum;

float avg;

Scanner buf = new Scanner(System.in);

System.out.print("Enter first number : ");

a = buf.nextInt();

System.out.print("Enter second number : ");

b = buf.nextInt();

/*Calculate sum and average*/

sum = a + b;

avg = (float)((a + b) / 2);

System.out.print("Sum : " + sum + "\nAverage : " + avg);

}

}

Explanation:

hope it helps!!!!

Similar questions