Computer Science, asked by shardul1925, 1 year ago

Hello and Good Evening Everyone!!!!


Please solve the Program 9.5 in JAVA language.

Class-9(CICSE)

Subject-Computer Science.

Attachments:

Answers

Answered by nitish8089
2
public class Test
{
public static int median(int a,int b,int c){
return (int)(Math.min(Math.min(Math.max(a,b), Math.max(b,c)),Math.max(a,c)));
}
public static void main(String[] args) {
System.out.println(Test.median(7,3,9));
System.out.println(Test.median(29,-14,11));
}
}

shardul1925: mere hisab se toh 71 hoga...lakin compiter 72 dikha raha hain bro
nitish8089: how solve it...
shardul1925: matlab
nitish8089: m=n++(12)*5// actually assignment value of n is 12 but after that increment so (post increment operator n++ so n=13) +--n(12) // output::: 72
shardul1925: accha.. bahut bahut dhanyadwad apka........
shardul1925: bhaiya ye....variable description or mnemonic code kya hota hain
nitish8089: topic bata sakte ho kis se related hai... kyuunki iske do answer hai.
shardul1925: All programs should be written woth java as the base.Each program should also be written using variable description or mnemonic codes such that the logic of the program is clearly depicted.
nitish8089: isme just variable ka naam is parkar dena ki datatype bhi samajh aaye..
shardul1925: ohh...thxx bro
Answered by Anonymous
11

Hey there!





Here's your code.




// Java program to print the middle value of the three integer using if - else statement

// Written by Mahnaz

 

public class MiddleValue

{    

   public static int median(int a, int b, int c)  

   {  

       if (a > b)  

       {  

           if (b > c)  

               return b;  

           else if (a > c)  

               return c;  

           else

               return a;  

       }  

       else

       {

           if (a > c)  

               return a;  

           else if (b > c)  

               return c;  

           else

               return b;  

       }  

   }  

     

   public static void main(String[] args)  

   {  

       System.out.println(median(1, 2, 3));

       System.out.println(median(1, 3, 2));

       System.out.println(median(2, 1, 3));

       System.out.println(median(2, 3, 1));

       System.out.println(median(3, 1, 2));

       System.out.println(median(3, 2, 1));

   }  

}





_______________________________

See the attachment for proper review.

_______________________________

Attachments:

shardul1925: thxx
Anonymous: Pleasure to help you. :)
nitish8089: whom change your answer..
Anonymous: I just modified my code.
nitish8089: actually earlier answer had an error but now perfect..
nitish8089: but how would you edit after time expire...
shardul1925: bcoz he is moderator..thts why
Similar questions