Thursday, February 18, 2021

 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

  3.WAP IN JAVA TO INPUT THREE NUMBERS AND COUNT HOW MANY OF THEM ARE EVEN .   import java.util.*; class Prog {   public static ...