ITEC 120 LAB 17 | Back to Lab index page |
Fun with arrays
You only need one java file with a main method for this project.
You will write a program which will read integers into an array and do some manipulations to the array.
Sample run:
User inputs: | java lab17 < ints.txt |
Program outputs: | How many
numbers will be entered? Enter num 1:Enter num 2:Enter num 3:Enter num 4:Enter num 5:Enter num 6:Enter num 7:Enter num 8:Enter num 9:Enter num 10:Enter num 11:Enter num 12:Enter num 13:Enter num 14:Enter num 15:Enter num 16:Enter num 17: 23 34 56 45 88 77 66 55 44 9 8 7 6 5 4 3 2 There were 9 even numbers. 2 3 4 5 6 7 8 9 44 55 66 77 88 45 56 34 23 |
Redirection -
Ever get tired of typing input into your programs? You can redirect input from a file instead. You need your input typed into a text file, which needs to be in the same directory as the program you want to run. At the command line, type java programname < inputfile, for example:
java lab17 < ints.txt
and lab17 will run, getting its input
from ints.txt instead of the keyboard. The above output was created by the input
in ints.txt.
Once you have your program working, show your lab to the Peer Instructor to
be checked off. Run the program with ints.txt and ints2.txt
as input.