?
Solved

input.readLine()

Posted on 2005-03-17
6
Medium Priority
?
156 Views
Last Modified: 2010-04-17
how to use the above function..
i've included the code belows

import java.io.*;

public class Testing
{

      public static void main(String args[]) throws
java.io.IOException
      {

      System.out.println("Enter a name");
      String search = input.readLine();
      System.out.println(search);
      }
}


but when run they will show that can't resolve symbol at the "input" word....

how to actually use the method?

0
Comment
Question by:yuen_jk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
6 Comments
 
LVL 21

Accepted Solution

by:
MogalManic earned 500 total points
ID: 13564675
the class input does not exist in the main function.  Try adding the following on the 1st line of the main function:
        BufferedReader input=new BufferedReader(new InputStreamReader(System.in));
This will read from the standard input and then buffer the results (the BufferedReader class has the readLine() method)
0
 
LVL 15

Expert Comment

by:Ralf Klatt
ID: 13565298
Hi,

MogalManic is right with "BufferedReader" ... but you shouldn' place it on the 1st line of the main function ... I'd suggest doing it that way:

import java.io.*;

public class Testing
{
     static BufferedReader input = new BufferedReader (new InputStreamReader(System.in),1);
     /* the buffer is set to 1 beacuse of a known bug in Windows with JDK 1.1.3. and onwards! */

     public static void main(String args[]) throws java.io.IOException
     {
          System.out.println("Enter a name");
          String search = input.readLine();
          System.out.println(search);
     }
}


Best regards,
Raisor
0
 
LVL 15

Expert Comment

by:Ralf Klatt
ID: 13765530
Hi,

I think that I've added a small but not really unimportant information to this question.

My suggestion would be 75% MogalManic and 25% Raisor ...


Best regards,
Raisor
0
 
LVL 20

Expert Comment

by:Venabili
ID: 13768075
Raisor,

MogalManic's solution is working just fine... no problems.. at least I had no troubles with it last 5 years :)

Venabili
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
A short article about problems I had with the new location API and permissions in Marshmallow
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Starting up a Project
Suggested Courses
Course of the Month7 days, 23 hours left to enroll

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question