Java Problem -3 : How to calculate average ? Question with solution.

in #java7 years ago

Question: write methods that accepts two numbers and returns the average of the two numbers.

Solutions :

public class Ninetynine{

         Ninetynine(){
                              hello("Afjal");
                              system.out.println(average(3,4));
              }
       public void hello(String s){
                               System.out.println("Hello "+s);
       }
       double average(double x, double y){
                           return (x+y)/2;
        }
       public static void main(String [] args){
                           new Ninetynine();
        }

}

Output : 3.50
19665474_102271520424268_8254003595485697018_n.jpg

Coin Marketplace

STEEM 0.19
TRX 0.16
JST 0.033
BTC 64308.31
ETH 2810.43
USDT 1.00
SBD 2.65