Mary Jean
2009-08-31 16:54:35 UTC
To create your instant Christmas letter, simply fill in the boxes below and then click the Create button. You will then be able to copy and print the story on your own letterhead. For best results, you can put more than one sentence in each box. See the sample below for ideas.
Mark aka jack573
2009-09-04 11:47:27 UTC
Other solutions would be using a List, but a Vector would probably be better. The API for Vector is here: http://java.sun.com/javase/6/docs/api/java/util/Vector.html Here is a summary of the Vector from the API "The Vector class implements a growable array of objects. Like an array, it contains components that can be accessed using an integer index. However, the size of a Vector can grow or shrink as needed to accommodate adding and removing items after the Vector has been created." The only disadvantage of using the Vector is you need to use objects and not the primitive classes. But, Java gives you wrapper classes for the primitives, so you can put a primitive into a wrapper class, and get the primitive back. The wrapper classes are objects, so you can put it into a Vector. So lets say the inputs are ints. You would do something lilke this. Vector int num; Integer objNum; // you would need a way for the user to indicate they have stopped inputting the number. Let's assume that the user types -999 to stop the input. while (true) { // Output a message to ask the user to provide a number. num = // Get the input here. if (num == -999) { break(); } objNum = new Integer(num); vec.add( objNum ); } Now to go through all of the numbers you have got from input, you would do something like this. if ( ! vec.isEmpty() ) { int largest = vec.firstElement(); int smallest = largest; for (int i = 1; i < vec.size(); i++) { objNum = vec.elementAt( i ); num = objNum.intValue(); if (num > largest) { largest = num; } if (num < smallest) { smallest = num; } } // Output the largest and smallest. } else { // Output no input was received. } Hope that helps you out.
tuaamin13
2009-08-31 17:00:15 UTC
I forget the usage, but you can probably find some examples of variable input functions online.
Steve
2009-08-31 17:00:24 UTC
void printall(String... args) { System.out.println("There are "+args.length+" args"); for (String arg : args) { System.out.println(arg); } } Hope that helps.
ⓘ
This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...
|