Search This Blog

If you have any problem or question please write in the comments. We will try to solve and send you the solution. Not just that we will also post your problems solution on our blog.

Thursday, 1 September 2011

Java program to find average and add two numbers taken from user

Finding addition and average of two numbers is also very simple in java. As you will see it is little bit different from another program which finds sum and product of two numbers. There is its code:

import java.util.*;
class sumavg
public static void main (String args[])
Scanner in = new Scanner (;
int a,b,s,avg;
System.out.print ("\n\t Enter first number = ");
System.out.print ("\n\t Enter second number = ");
System.out.print ("\n\t sum = "+s);
System.out.print ("\n\t avg = "+avg);

          Look at this "avg=s/2" statement. We have sum of the numbers in s and that's why we are dividing s by 2 to calculate average of these numbers. You can also do that in a different way like: