Flash Website Builder- Trendy Site Builder is a Flash Site Building tool that helps users build stunning websites. Check Out Custom Custom Logo Design by LogoBee. Website Design and Free Logo Templates available.
 CodingForums.com numbers programming
 User Name Remember Me? Password

Before you post, read our: Rules & Posting Guidelines

Enjoy an ad free experience by logging in. Not a member yet? Register.
 11-10-2012, 12:52 PM PM User | #1 coding-beginner New to the CF scene   Join Date: Nov 2012 Posts: 1 Thanks: 0 Thanked 0 Times in 0 Posts numbers programming Hi, I've only just started java and I am trying to to make a program so that when a any line of digits are added it prints the count N for the numbers (how many numbers are in the line), the minumum and maximum of the line of numbers, their sum, and the average of all the numbers. Each of these specifications has to be printed on a new line. The program has a to be called NumberFor eg. >NumberFor 22.0 42.5 15.2 -2 6 4 -2 42.5 77.1 19.275 Currently I have: public class NumberFor { public static void main(String[] args) { double value = Double.parseDouble(args[0]); double sum = 0.0; //count N // first value read initialized min and max double max = StdIn.readDouble(); double min = max; // read in the data, keep track of min and max { if (value > max) max = value; if (value < min) min = value; } System.out.println(+ min); System.out.println(+ max); // sum of values double N = Double.parseDouble(args[0]); for (double i = 0.0; i < N; i++) { sum += value; } System.out.println(+ sum); //average double cnt = 0; while (!StdIn.isEmpty()){ sum += value; cnt ++; } double average = sum / cnt; System.out.println(+ average); } } and the only output i can get to work is the max
 11-10-2012, 12:54 PM PM User | #2 Philip M Supreme Master coder!     Join Date: Jun 2002 Location: London, England Posts: 17,487 Thanks: 200 Thanked 2,471 Times in 2,449 Posts This is the JavaScript forum. Java and Javascript are entirely different programming languages, in spite of the confusingly similar names. Rather like Austria and Australia! Ask a mod to move this thread to the right forum. __________________ All the code given in this post has been tested and is intended to address the question asked. Unless stated otherwise it is not just a demonstration.
 11-10-2012, 05:43 PM PM User | #3 Fou-Lu God Emperor     Join Date: Sep 2002 Location: Saskatoon, Saskatchewan Posts: 16,603 Thanks: 4 Thanked 2,598 Times in 2,567 Posts This is a bit unusual; you are working off of input for the application command, but you do not appear to use any additional methods or object types. Casting and parsing isn't IMO something that should be learned before method handling. The trick here is to simply ensure you have a double[] or Double[] to work with. PHP Code: ```         double[] dValues = new double[args.length];        for (int i = 0; i < args.length; ++i)        {            dValues[i] = Double.parseDouble(args[i]);        }  ``` Simple as that. You now work with only dValues to collect the information about the count, max/min (easy via sorting a copy), average, sum, whatever you want. Also, in the future please use [php][/php] or [code][/code] tags as it preserves the formatting.

 Bookmarks

 Thread Tools Rate This Thread Rate This Thread: 5 : Excellent 4 : Good 3 : Average 2 : Bad 1 : Terrible

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home :: Client side development     JavaScript programming         DOM and JSON scripting         Ajax and Design         JavaScript frameworks         Post a JavaScript     HTML & CSS     XML     Flash & ActionScript         Adobe Flex     Graphics and Multimedia discussions     General web building         Site reviews         Building for mobile devices :: Server side development     Apache configuration     Perl/ CGI     PHP         Post a PHP snippet     MySQL         Other Databases     Ruby & Ruby On Rails     ASP     ASP.NET     Java and JSP     Other server side languages/ issues         ColdFusion         Python :: Computing & Sciences     Computer Programming     Computer/PC discussions     Geek News and Humour Web Projects and Services Marketplace     Web Projects         Small projects (quick fixes and changes)         Medium projects (new script, new features, etc)         Large Projects (new web application, complex features etc)         Unknown sized projects (request quote)         Vacant job positions         Looking for work/ for hire         Project collaboration/ partnership         Paid work offers and requests (Now CLOSED)     Career, job, and business ideas or advice     Domains, Sites, and Designs for sale         Domains for sale         Websites for sale         Design templates and graphics for sale :: Other forums     Member Offers     Forum feedback and announcements

All times are GMT +1. The time now is 05:25 AM.