Search This Blog

Loading...
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.

Wednesday, 13 April 2011

Java program to calculate average of two numbers

import java.util.*;
class average
{
public static void main (String arg[])
{
Scanner in=new Scanner (System.in);
int a,b,avg;
System.out.print ("\n\t Enter first number = ");
a=in.nextInt();
System.out.print ("\n\t Enter second number = ");
b=in.nextInt();
a+=b;
avg=(a)/2;
if (avg>50)
System.out.println ("\n\t Error ");
else 
System.out.println ("\n\t Sum = "+a+"    Average = "+avg);
}
}

No comments:

Post a Comment