• 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
  • Bear Bibeault
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Ron McLeod
  • Tim Moores
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Vijitha Kumara

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: 49
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: 63791
209
  • 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: 10759
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: 63791
209
  • 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: 63791
209
  • 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.
 
When all four tires fall off your canoe, how many tiny ads does it take to build a doghouse?
global solutions you can do in your home or backyard
https://coderanch.com/t/708587/global-solutions-home-backyard
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!