Win a copy of Java XML & JSON this week in the XML and Related Technologies forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Devaka Cooray
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

How do I print out Array Mirror?  RSS feed

 
Greenhorn
Posts: 1
Java MySQL Database Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, in my practice, I have implemented the Java codes below, however, I am not getting the expected output.
What would I need to modify on this code?


 
Ranch Hand
Posts: 43
1
Java Netbeans IDE Oracle
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You try to use append method but there is no built-in method and you didn't write it manually. If you want to get output like this  [ 1,2,3,4,5,5,4,3,2,1 ] you can create a new array and then copy elements from both arrays (initial array and returned from newArray method). And by the way while writing class name you should start capital letter (should be ArrayMirror not arrayMirror).

Welcome to the Ranch
 
Marshal
Posts: 62801
203
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch again

There aren't any methods in Arrays to reverse an array, but it is quite easy to write a for loop to traverse your array backwards.If you aren't familiar with that format, search my posts in this forum for for traverse array backwards and you will probably find something useful there.
 
Bartender
Posts: 10720
68
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Brendar Williamson wrote:What would I need to modify on this code?


Well, you've already used "+" quite successfully to concatenate Strings, but then you decided to use something called "append" (specifically Arrays.append()) which, as you've been told, doesn't exist.

Another point: You called your method newArray(), which doesn't really mean very much, and specifically doesn't describe what it does.
Can you think of a better name for it?

Winston
 
Campbell Ritchie
Marshal
Posts: 62801
203
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:. . . . search my posts in this forum for for traverse array backwards . . . .

I am told that link doesn't work properly: try this instead.
 
Campbell Ritchie
Marshal
Posts: 62801
203
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That *@!¢ link I posted still doesn't seem to work. I still can't find the posts with the loops written nicely.
 
All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!