Q:

Java program to find sum and average of two integer numbers

0

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Consider the program:

// 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);
    }
}

Output

Enter first number : 100 
Enter second number : 200 
Sum : 300 
Average : 150.0

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now