Results 1 to 4 of 4
  1. #1
    Shyam Singh is offline Member
    Join Date
    Jun 2008
    Posts
    48
    Rep Power
    0

    Default who to take user input ,not by console...

    pls send me a simple example for taking user input which should be used in other calss ..
    • i suppose it will not be possible to take that input in one other meyhod except main() . i think it only be possible by System.in.readline().


    Help me its urgent.... give me very simple example

  2. #2
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Default

    Java Code:
    System.in.read();
    The returns what the user typed as though one had coded
    Java Code:
    int anInt = (int)'c';//
    People are going to laugh at me for the cast, it is an auto-conversion, all widening conversions are implicit generally.

    System.in.read(); will not continue operation of the Java Virtual Machine until the user types something. I try to use a simple file and do reading from that. There is a Scanner class that is popular for reading System.in but that may not be what you need.

    Are you just trying to get going?

  3. #3
    Shyam Singh is offline Member
    Join Date
    Jun 2008
    Posts
    48
    Rep Power
    0

    Default

    import java.lang.*;

    public class ctruct
    {
    public static void main(String args[])
    {

    String ename;
    System.out.println("Enter emp name");
    ename=System.in.readline();
    System.out.println("Enter emp name -->"+ename);
    }
    }

    this is the lay man code .. i will learn scanner class later .. 2 -3 yrs back i use to take i/p by system.in.readln() or somthing like that..

  4. #4
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Default

    It is difficult to decipher your qestion. I tried to reply earlier when you posted but the cgi would not propagate your second post.
    Java Code:
    // maybe this is what poster asking
    class FirstClass{
      public static void main(String[] args){
          SecondClass s = new SecondClass();
          String t = System.in.readline();// or scanner
           s.doSomething(t);
    Is having another class written to work with the readline(); what you are trying to grasp?

Similar Threads

  1. How to get input from Console
    By karma in forum New To Java
    Replies: 8
    Last Post: 08-13-2010, 10:32 PM
  2. how to get input from User
    By Alvaro in forum New To Java
    Replies: 7
    Last Post: 01-16-2010, 12:02 AM
  3. how to take input from console in jsp
    By veena in forum New To Java
    Replies: 1
    Last Post: 05-06-2008, 05:39 AM
  4. cant take input from user
    By new_1 in forum New To Java
    Replies: 6
    Last Post: 12-25-2007, 08:38 AM
  5. Taking input from console
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-05-2007, 05:47 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •