Ask your own question, for FREE!
Computer Science 18 Online
OpenStudy (anonymous):

what i've done wrong in this solution according to this exercise create an aplication in Java that reads 2 numbers as input and then calculates and bills maximums minimums and average of these 4numbers ..solve this using Math methods ..please help me i'm a beginner import java.math.*; public class prove { public static void main(String[] args) { String name =args[0]; String name2=args[1]; int b=Math.max(name,name2); } } @Mathematics

OpenStudy (anonymous):

Stop spamming the question board. You've posted your question 7 times in the last 3 hours, and they were 7 of the last 9 questions on the groups I'm in. People will see your question when they see it and will reply to it if they can. Spamming is a good way to get people to NOT answer your question. Having said that, you need to be more clear about the requirements. Are you supposed to read the numbers from the command line or from System.in? (Command line would be easier.) You need to use Integer.parseInt() to turn a String into an int. java.lang.Math has max() and min() functions that take two values only, so you'll have to use them on only two numbers at a time. It doesn't have anything to help with the average, but that's just the sum of the numbers divided by the number of numbers. You aren't using, and don't need to use, anything from java.math. The general strategy here is to keep four variables, and update them with each new number. minimum, maximum, sum, and count. Start minimum at Integer.MAX_VALUE, start maximum at Integer.MIN_VALUE, and start sum and count at 0. For each number you get, if it's smaller than the minimum, make it the new minimum, if it's larger than the maximum, make it the new maximum, and add the number to sum, and add 1 to the count. When you've processed all the numbers, the average will be sum/count (but cast them to doubles so you keep the fractional part of the division). Oh, you have to use Math.max/min. Instead of checking if the numbers are smaller or larger than min and max, let the new min be Math.min() of the current min and the new number. Similarly for the max.

OpenStudy (anonymous):

Sorry that was because my computer was slow and it didn't show if i had already posted the question or not ..I got the idea but I have to get the values from run configuration-my arguments there is the place where i should write my arguments and then put them into maximum minimum etc. and we haven't learnt yet this Integer.parseInt() and I have to do it using math methods not others than you anyway

OpenStudy (anonymous):

import java.math.*; public class fdsfsd { public static void main (String[] args) { String s="2"; String b="7"; String a="10"; String e="45"; int c = new Integer(s).intValue(); int d = new Integer(b).intValue(); int f = new Integer(a).intValue(); int r = new Integer(e).intValue(); int max1=Math.max(c,d); System.out.println(max1); int max2=Math.max(f,max1 ); System.out.println(max2); int max3=Math.max(max2,r); System.out.println(max3); int sum=c+d+f+r; int ave=sum/4; System.out.println(ave); am I right with this ???

OpenStudy (anonymous):

What happened when you tried to compile and run it?

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!