Skip to Content
Java How to Program, Early Objects, 11th Edition
book

Java How to Program, Early Objects, 11th Edition

by Paul J. Deitel, Harvey Deitel
June 2017
Beginner
1296 pages
69h 23m
English
Pearson
Content preview from Java How to Program, Early Objects, 11th Edition
... an array using command-line arguments.
 3
 4   public class InitArray {
 5      public static void main( String[] args) {
 6         // check number of command-line arguments
 7         if ( args.length != 3) {
 8            System.out.printf(
 9               "Error: Please re-enter the entire command, including%n" +
10               "an array size, initial value and increment.%n");
11         }
12         else {
13            // get array size from first command-line argument
14             int arrayLength = Integer.parseInt(args[0]);
15            int[] array = new int[arrayLength];
16
17            // get initial value and increment from command-line arguments
18             int initialValue = Integer.parseInt(args[1]);
19             int increment = Integer.parseInt(args[2]);
20
21            // calculate value for each array element
22            for (int counter = 0; counter < array.length; counter++) {
23 array[counter] ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17

Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17

Kishori Sharan, Adam L. Davis
Learning Java, 5th Edition

Learning Java, 5th Edition

Marc Loy, Patrick Niemeyer, Daniel Leuck
Java in a Nutshell, 8th Edition

Java in a Nutshell, 8th Edition

Benjamin J. Evans, Jason Clark, David Flanagan

Publisher Resources

ISBN: 9780134751962