1. WAP IN JAVA TO INPUT A NUMBER WHICH CONSIST OF TWO DIGITS AND DISPLAY AVERAGE OF THE DIGITS.
import java.util.*; //import java packages
class Prog //declare the class
{
public static void main(String args[ ]) // “main” method
{
Scanner ob=new Scanner(System.in);
int num; //declare the variable
System.out.print(“Enter the number”); //input the value
num=ob.nextInt( ) ;
int x1=num%10; //extract the digits
int x2=num/10 ;
double avg=(double)((double)(x1)+(double)(x2))/2; //calculate average
System.out.println(“Average of the digits :”+avg); //display the average
} //end of “main”
} //end of class
No comments:
Post a Comment