aspose file tools*
The moose likes Beginning Java and the fly likes Arrays Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Arrays" Watch "Arrays" New topic
Author

Arrays

maya jain
Greenhorn

Joined: Feb 22, 2011
Posts: 5
Hii,

I am trying to write a program in which i can input a string in an array a and then display it. I wrote this code, but it doesn't work, I know I made a mistake at line 7, please help me out.

Regards,
Maya
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Some pointers (some more important than others, but all hopefully useful):

  • Java class names by convention start with an upper case letter. This seems trivial, but in the long run makes working with code much easier
  • The line String [] a = new String[1]; creates an array with one element. Are you sure you will only ever have one element? If not, consider on of the Collections classes that can grow and have methods to return arrays. (see java.util package)
  • String b = reader.readLine() only reads one line. Are you sure there will only ever be one line?
  • Have you looked at java.io.Console at all?
  • notes = new String(b); will not compile because you have not defined notes.


  • JavaRanch FAQ HowToAskQuestionsOnJavaRanch
    fred rosenberger
    lowercase baba
    Bartender

    Joined: Oct 02, 2003
    Posts: 11475
        
      16

    "It doesn't work" doesn't really make it all that easy for us to help you. Tell us HOW it doesn't work. Tell us what you are doing when it doesn't work, and what you think it should do. The easier you make it for someone who reads your post, the more likely you will get an answer that solves your problem.


    There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
    Prasanna Kumaar
    Ranch Hand

    Joined: Feb 08, 2011
    Posts: 30
    Problem is in the following line

    notes = new String(b);

    And it is because you did not declare 'notes' as a variable...
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Arrays