what is the function that allows to accept typed input


usually i right import java.io.*;

but eclipse has got its own function . what is it?

Recommended Answers

All 4 Replies

Are you referring to the fact that Console input does not work in Eclipse (or other industrial-grade IDE's)? If so, you can use a reader on System.in like this:

try {
         BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
         System.out.print("Type name: ");
         String name = reader.readLine();
         System.out.println("Hello " + name);
      } catch (IOException e) {
         e.printStackTrace();
      }

james, i remember that it is one line .. it is a long line..not a class. but i forgot what it was

What I posted was code fragment, not a class. If you read it you will see one line to declare the reader and one line to read from it. The rest is to demo how it works.
I don't believe you will find a shorter solution.

Use the Scanner class for the same. I think this tutorial does a fair job of explaining the same.

commented: thanks s.o.s +0
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.