Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Arrays

 
maya jain
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
  •  
    fred rosenberger
    lowercase baba
    Bartender
    Posts: 12198
    35
    Chrome Java Linux
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    "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.
     
    Prasanna Kumaar
    Ranch Hand
    Posts: 30
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Problem is in the following line

    notes = new String(b);

    And it is because you did not declare 'notes' as a variable...
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic