Pow1032 etc for example return a random value between

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: docs CPSC 324 ‐‐ Spring 2010 16 8 1/19/10 Command-Line Parameters Passed to main as an array of Strings public staLc void main(String args) So, if we issue the command: java MyEliza terms.txt defaults.txt •  How do we check if we have the right number of args? if(args.length < 2) { // print usage message, and call System.exit(64); } •  How do we get the first and second arg? String termsFileName = args[0]; String defaultsFileName = args[1]; CPSC 324 ‐‐ Spring 2010 17 Math Functions •  The Math class provides various helper functions double x = Math.random(); // random value in [0.0, 1) double y = Math.sqrt(15); double z = Math.pow(10, 3.2); etc. •  For example, return a random value between 0 and 9 int x = (int) (Math.random() * 10); CPSC 324 ‐‐ Spring 2010 18 9 1/19/10 Static Methods •  Classes can have static fields and methods •  The Math methods are examples of static methods public class...
View Full Document

This document was uploaded on 03/18/2014 for the course CPSC 324 at Gonzaga.

Ask a homework question - tutors are online