0

Is there a "neater" way to code the following? (It prints the 5 data elements in an array.)

System.out.println("All the values in the array are: ");
System.out.println(+ array1[0]);
System.out.println(+ array1[1]);
System.out.println(+ array1[2]);
System.out.println(+ array1[3]);
System.out.println(+ array1[4]);

Thanks,
Bud

4
Contributors
4
Replies
9
Views
11 Years
Discussion Span
Last Post by peter_budo
Featured Replies
  • 1
    Narue 5,707   11 Years Ago

    >Is there a "neater" way to code the following? [code] System.out.println ( "All the values in the array are: " ); for ( T x: array1 ) System.out.println ( x ); [/code] Change T to whatever the type of the array is. Or, if you aren't up to the latest … Read More

1

>Is there a "neater" way to code the following?

System.out.println ( "All the values in the array are: " );
for ( T x: array1 )
  System.out.println ( x );

Change T to whatever the type of the array is. Or, if you aren't up to the latest version of Java:

System.out.println ( "All the values in the array are: " );
for ( int i = 0; i < array1.length; i++ )
  System.out.println ( array1[i] );
Comments
elegent way!
-2

a neater way of getting values from an array! Good work, buddy.

System.out.println ( "All the values in the array are: " );
for ( T x: array1 )
  System.out.println ( x );

Thanks.

Comments
Now let me "repay" your "kindness" of false accusation by down-voting so you can see that first vote wasn't my. Have nice day, and get some manners.
0

@rotten69 was it worth to reopen 6 year old thread? (Created 02-05-05)

Thread closed, before another time-traveler arrival

Edited by peter_budo: n/a

Comments
Why the HECK was I given a -1? Because I added a reply in a too old thread!!
This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.