Write a program in Java to find average & median of 3 numbers.
This isn't a question. You haven't even attempted to do this....However, I will write the idea program to do so. In the future, you need to attempt this first and show your progress.
//imports go here //You'd want to input arrays and the use of the System.out."method". I don't remember //Them off the top of my head. public class Example { public static void main(String args[]) { int threeNum[] = {5, 1, 2}; System.out.println("The median of threeNum is: " + median(threeNum) + "."; System.out.println("The average of threeNum is: " + average(threeNum) + "."; } private double median(int threeNum[]) { int sorted[] = Arrays.sort(threeNum); //assuming the 3 numbers return sorted[2]; //Again, I would never use this because this is just 3 number example } private double average(int threeNum[]) { double sum = 0; for(int i = 0; i < threeNum.length; ++i) sum += threeNum[i]; return ((double)sum / i); }
Join our real-time social learning platform and learn together with your friends!