How do i get input from user?

For example if i wanted to ask "Whats your favorite number" and then get the input from the user and assign it to a variable how would i go about doing that?
Any help would appreciated

hope this helps
import java.io.*;
public static void main(String[] args)
  //this is the important part
  BufferedReader in = new BufferedReader( new InputStreamReader(System.in) );
  String response = "";
  System.out.println("What is your favorite color?");
  try{
       //now read the line
       response = in.readLine();
  }catch(Exception e){
        //enter error code here
  System.out.println("I like " +response+ " as well!");
}

Similar Messages

  • How can i get input from user in Workflows

    Hello professionals,
    I'm new to SAP B1 Workflow, i have created some workflows and they all worked fine.
    But, I am wondering, How can i get input from user?. For example, i want to display list of options to choose between them and route the workflow based on the selected option. I don't want to use the exclusive gateway and check for some conditions, i want to get input from user.
    How can i do that?
    Thanks in advance,
    Kareem Naguib

    Hi,
    Please refer SAP help file:
    http://help.sap.com/saphelp_sbo900/helpdata/en/b8/1f9a1197214254b79bcf8f93f9fff9/content.htm?frameset=/en/44/c4c1cd7ca22…
    Thanks & Regards,
    Nagarajan

  • How to  Get input from  User and Display it's Value

    Hi ,
    I need to get 2 inputs from user and to display it's Mutilple Value.
    The Below Code is working fine to get 2 Input's from user,but it display a Junk value as a Result .How to
    overcome this Problem. I need to display it's Mutilple(a*b) value of "a " and " b".
    import java.io.*;
    class Mul{
    static int a=0;
    static int b=0;
    static int Count=0;
    public static void main(String args[])throws IOException{
    BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
    do{
    a=(char)br.read();
    Count++;
    b=(char)br.read();
    if(Count==2)
    System.out.println("The Multiplied Value is "+a*b);
    }while(Count<2);
    }

    Changed to Integer but still the problem persists.
    import java.io.*;
    class Mul{
    static int a=0;
    static int b=0;
    static int Count=0;
    public static void main(String args[])throws IOException{
    BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
    do{
    a=(int)br.read();
    Count++;
    b=(int)br.read();
    if(Count==2)
    System.out.println("The Multiplied Value is "+a*b);
    }while(Count<2);
    }

  • How to Get Input From User and Display Result

    Hi ,
    I need to get 2 inputs from user and to display it's Mutilple Value.
    The Below Code is working fine to get 2 Input's from user,but it display a Junk value as a Result .How to
    overcome this Problem. I need to display it's Mutilple(a*b) value of "a " and " b".
    import java.io.*;
    class Mul{
    static int a=0;
    static int b=0;
    static int Count=0;
    public static void main(String args[])throws IOException{
    BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
    do{
    a=(char)br.read();
    Count++;
    b=(char)br.read();
    if(Count==2)
    System.out.println("The Multiplied Value is "+a*b);
    }while(Count<2);
    }

    Hi ,
    I need to get 2 inputs from user and to display it's
    Mutilple Value.
    The Below Code is working fine to get 2 Input's from
    user,but it display a Junk value as a Result .How
    to
    overcome this Problem. I need to display it's
    Mutilple(a*b) value of "a " and " b".
    import java.io.*;
    class Mul{
    static int a=0;
    static int b=0;
    static int Count=0;
    public static void main(String args[])throws
    IOException{
    BufferedReader br =new BufferedReader(new
    InputStreamReader(System.in));
    do{
    a=(char)br.read();This line will get you the ascii-value of the typed character.
    This line will not get you the value typed in.
    Try looking for Integer.parseInt()...
    Count++;
    b=(char)br.read();
    if(Count==2)
    System.out.println("The Multiplied Value is "+a*b);
    }while(Count<2);

  • How do i get input from the user?

    For example if i wanted to ask "Whats your favorite number" and then get the input from the user and assign it to a variable how would i go about doing that?

    hi,
    if you want to get input from your console your should work with io(input and output).The BufferedReader class, InputStreamReader class
    you should import "java.io.BufferedReader" and "java.io.InputStreamReader" package, and do something like this:
    BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
    String favoriteNumber;
    System.out.println("Whats your favorite number ");
    favoriteNumber = input.readLine();
    System.out.println ("Your favorite Number Is " + favoriteNumber);
    if its a gui you should import "javax.swing.JOptionPane" and do the following
    String favoriteNumber = JOptionPane.showInputDialog(null, "Enter your favorite Number", "Favorite Number", JOptionPane.INFORMATION_MESSAGE);
    anjiie([email protected]).

  • Get input from user and create a file and run a script in command line.

    Hi all,
    i'm trying to get a input from user and write it into a file named alpe.jacl
    To get multiple userinputs like address and jobtitle etc etc in the same single window.
    and the code will save the inputs in alpe.jacl one by one in a new line like
    nameis name
    address russia
    jobtitle dev
    So i coded like below.
    Though GUI for user input looks dull Its working fine.
    Now I want this code to perform one more task which is the GUI will contain one more button INSTALL with OK and CALCEL .
    and when after putting all inputs and creating the alpe.jacl file if someone clicks INSTALL it should start ./install.sh script present at the same folder which contains some unix shell commands.
    Here am not able to figure out how to go further...
    One more thing after all the inputs given when I am clicking on the OK button its closing the window instantly which i dont want. I want it like it should wait till someone press CANCEL to exit.
    Please some one help me.
    import javax.swing.*;
    import java.io.*;
    public class file
    public static void main(String []args)throws IOException
    FileWriter ryt=new FileWriter("alpe.jacl");
    BufferedWriter out=new BufferedWriter(ryt);
    JTextField wsName = new JTextField();
    JTextField sName = new JTextField();
    JTextField cName = new JTextField();
    Object[] message = {    "Web Server Name:", wsName,"Server Name:", sName,"Cluster Name:", cName};
    int answer = JOptionPane.showConfirmDialog(    null, message, "Enter values", JOptionPane.OK_CANCEL_OPTION);
    if (answer == JOptionPane.OK_OPTION){    String webserver = wsName.getText();
    String server = sName.getText();
    String cluster = cName.getText();
    out.write("set webservername " +wsName.getText()+"\n");
    out.write("set ClusterName " +cName.getText()+"\n");
    out.write("set ServerName " +sName.getText()+"\n");
    out.close();
    }}Thanks,
    Ricky

    Thanks a lot.
    Is there any way through which i can assign a scroll bar to my panel.
    As when the number of user inputs grows the GUI becomes more bulky and some of the fields are not showing up.
    Cheers
    _Ricky                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • How can i take input from user?

    class input{
    public static void main(String args[]){
    int i,j,result;
    //i want to take input here from user.
    result=i+j;
    System.out.println(result);
    }

    here's the code which takes input of i , j from user and adds it
    <code>
    public static void main(String[] args)
              int i=0;
              int j=0;
              String s = null;
              System.out.println("Enter value of 'i'");
              InputStreamReader isr = new InputStreamReader ( System.in );
              BufferedReader br = new BufferedReader ( isr );
              try
              s = br.readLine ();
              i=Integer.parseInt(s);
              System.out.println("Enter value of 'j'");
              isr = new InputStreamReader ( System.in );
              br = new BufferedReader ( isr );
              s = br.readLine ();
              j=Integer.parseInt(s);
              System.out.println("Enter value of 'i+j ='"+(i+j));
              catch(Exception e){}
    </code>

  • How can i get input from microphone?

    Hi,
    I am trying to create a program that essentially tries to detect the
    Microphone . Pls tell how can i perform this. Any suggestions, pls?

    http://www.bulletsandbones.com/GB/GBFAQ.html#midionreal

  • How to Get Input from Command Prompt?

    How can i get input from command prompt like
    C:\
    or linux ?
    (Here's what I use now)
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String line;
    Whlie((line=in.readLine())!= null)
    { System.out.prinln( line) ; }
    IS THERE A BETTER WAY?

    The main method within a java class accepts command line input through a String array.
    In this example args is the String array. You can access the parameters as args[0] for the first parameter, args[1] for the second parameter, etc....
    The usage for the example below would be :
    c:\EDIFormat file1 file2
    Where args[0] would equal file1 and args[1] would equal file2.
    public class EDIFormat {
    public static void main(String[] args) {
              if (args.length < 0) {
                   System.out.println("No Parameters supplied. Exiting....");
                   // open input and output files
                   EDIFiles(args[0], args[1]);
    Hope that helps!

  • How to calculate the total from users input in switch?

    I dont know how to hold the input from user. But here is part of my coding :
    System.out.println ("Type 1 for buying Ruler"+
    "\nType 2 for buying Pencil");
    stationaries = console.nextInt();
    switch (stationaries)
    case 1 : System.out.println("Ruler per unit : MYR1");
    System.out.println("How much does you want? : ")
    wantRuler = console.nextInt();
    sum = wantRuler * 1;
    break;
    case 2 : System.out.println("Pencil per unit : MYR2");
    System.out.println("How much does you want? : ")
    wantPencil = console.nextInt();
    sum = wantPencil * 2;
    break;
    How can I calculate the total for both of the stationaries if user wants 5 for ruler and 6 for pencil?

    Note: This thread was originally posted in the [Java Programming|http://forums.sun.com/forum.jspa?forumID=31] forum, but moved to this forum for closer topic alignment.
    Use code tags to post codes -- [code]CODE[/code] will display asCODEOr click the CODE button and paste your code between the {code} tags that appear.

  • Getting input from textbox as "console"

    Hi all. I am learning C# and have a Windows forms project that I am working on to learn various techniques. Basically it has a text box that I use to mimic a console. The user enters a command followed by the Enter key and the program reads that in and interprets
    it. I also have some rudimentary "batch" commands, such as IF/THEN, INPUT and PRINT.
    The application has two main components: The form and a class. The form takes care of interpreting the commands that the user enters and the class implements the three batch commands (more to follow in the near future). The issue that I am having is that
    sometimes (maybe 2%) the INPUT functionality does not work. When I enter a string and press Enter an empty string is returned. I have tried to debug this as much as I can, but it is difficult since this problem only happens once in a while.
    I have extracted the INPUT functionality and duplicated it in a simple app which I present here. The test app contains one button called btnConRead and a multi line text box called txtConsole. Clicking the button "forces" the app into "run"
    mode where the batch commands are interpreted. For this example I run the code that runs when an INPUT command is being processed. The app prompts with "OK" and waits for the user to type something in. When the user presses the Enter key the entered
    string is echoed on the console. The form module contains this code:
    string sKBBuf = ""; //App wide KB buffer when form Key preview is enabled.
    bool bEnter;
    private delegate void DisplayMsgDelegate(string sMsg);
    private void cEventPrint(object sender, PrintDataEventArgs e)
    Display(txtConsole, e.sPrintLine);
    private void cEventRead(object sender, ReadDataEventArgs e)
    //Event that reads text from the console and returns it.
    //This event requires input from the user. It traps the program here until the user
    //presses Enter.
    //Clear the KB buffer.
    sKBBuf = "";
    //Loop incessantly until user presses Enter key or Stop key (s).
    do
    //Braindead.
    } while (!bEnter);
    if (bEnter)
    //User pressed the Enter key, return the KB buffer.
    e.sReadLine = sKBBuf;
    //Empty buffer.
    sKBBuf = "";
    //Reset Enter key flag.
    bEnter = false;
    //Push CRLF to console.
    Display(txtConsole, Environment.NewLine);
    private void DisplayMsg(string sMsg)
    txtConsole.AppendText(sMsg);
    private void Display(TextBox txtOutput, string sMsg, bool bToCon = true)
    //Check output to console flag.
    if (bToCon)
    if (txtOutput.InvokeRequired)
    txtOutput.Invoke(new DisplayMsgDelegate(DisplayMsg), sMsg);
    else
    txtOutput.AppendText(sMsg);
    private void GetConInput()
    clsExample cEx = new clsExample();
    cEx.ReadData += cEventRead;
    cEx.PrintData += cEventPrint;
    System.Threading.Thread runThread = new System.Threading.Thread(() =>
    cEx.Process();
    this.KeyPreview = false;
    this.KeyPreview = true;
    runThread.Start();
    private void btnReadCon_Click(object sender, EventArgs e)
    //Prep stuff
    sKBBuf = "";
    txtConsole.Focus();
    Display(txtConsole, "OK" + Environment.NewLine);
    //Read console textbox
    GetConInput();
    private void Form1_KeyPress(object sender, KeyPressEventArgs e)
    bEnter = e.KeyChar == 13;
    //Save to buffer. At this time I am not distinguishing from letter or digits.
    //But I do need to check for a BS.
    if (e.KeyChar == 8)
    //Yeah, BS, remove the last char, if any.
    if (sKBBuf.Length > 0)
    sKBBuf = sKBBuf.Substring(0, sKBBuf.Length - 1);
    else
    sKBBuf += e.KeyChar;
    The class is called clsExample and contains the following code:
    //Event raised when data needs to be printed to console.
    public event EventHandler<PrintDataEventArgs> PrintData;
    //Event raised when data needs to be read from console.
    public event EventHandler<ReadDataEventArgs> ReadData;
    protected virtual void OnReadData(ReadDataEventArgs e)
    EventHandler<ReadDataEventArgs> handler = ReadData;
    if (handler != null)
    handler(this, e);
    protected virtual void OnPrintData(PrintDataEventArgs e)
    EventHandler<PrintDataEventArgs> handler = PrintData;
    if (handler != null)
    handler(this, e);
    public void Process()
    ReadDataEventArgs argsRead = new ReadDataEventArgs();
    PrintDataEventArgs args = new PrintDataEventArgs();
    string sMsg = "";
    //Get input from user.
    OnReadData(argsRead);
    if (argsRead.sReadLine.Length > 0)
    //I have something
    sMsg = argsRead.sReadLine;
    else
    //No data
    sMsg = "*";
    args.sPrintLine = sMsg + Environment.NewLine;
    OnPrintData(args);
    Plus two more support classes for the Print and Read events:
    public class PrintDataEventArgs : EventArgs
    public string sPrintLine { get; set; }
    public class ReadDataEventArgs : EventArgs
    public string sReadLine { get; set; }
     All the above was necessary so that the Process procedure running in a different thread could interact with the UI elements in the main form. The above mostly works, but I wonder if I am doing it the right way. I don't particularly like the use of
    global flags, such as bEnter or having empty loops to just "kill" time, such as the one found in the cEventRead procedure.
    In the cEventRead procedure I had the if() block immediately following the empty loop inside
    the loop and moved it out of there to see if this made any difference, but apparently it did not. Can anyone provide any feedback or suggestions of what I could change to make it work 100% of the time? I appreciate your time and effort. Thank you, Saga
    You can't take the sky from me

    Hi all. I am learning C# and have a Windows forms project that I am working on to learn various techniques. Basically it has a text box that I use to mimic a console. The user enters a command followed by the Enter key and the program reads that in and interprets
    it. I also have some rudimentary "batch" commands, such as IF/THEN, INPUT and PRINT.
    //Loop incessantly until user presses Enter key or Stop key (s).
    do
    //Braindead.
    } while (!bEnter);
    Hi Saga,
    Please don't use such kind of loop in your code, if you want to monitor the user input, just use the KeyPress event provided by the TextBox control.
    Control.KeyPress
    Event
    If you just want to execute some standard commands, I recommend that you use
    Process to start cmd.exe to execute the command, for example:
    void ExecuteCommand(string command)
    int exitCode;
    ProcessStartInfo processInfo;
    Process process;
    processInfo = new ProcessStartInfo("cmd.exe", "/c " + command);
    processInfo.CreateNoWindow = true;
    processInfo.UseShellExecute = false;
    // *** Redirect the output ***
    processInfo.RedirectStandardError = true;
    processInfo.RedirectStandardOutput = true;
    process = Process.Start(processInfo);
    process.WaitForExit();
    // *** Read the streams ***
    string output = process.StandardOutput.ReadToEnd();
    string error = process.StandardError.ReadToEnd();
    exitCode = process.ExitCode;
    Console.WriteLine("output>>" + (String.IsNullOrEmpty(output) ? "(none)" : output));
    Console.WriteLine("error>>" + (String.IsNullOrEmpty(error) ? "(none)" : error));
    Console.WriteLine("ExitCode: " + exitCode.ToString(), "ExecuteCommand");
    process.Close();
    If it's powershell script, you can also use the existing library to execute it, check this blogpost:
    Executing PowerShell scripts from C#
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • How can i get all the users from weblogic server?

    how can i get all the users from weblogic server?
    i have configurated a LDAP server using iPlanet and
    in weblogic server console i see those users from LDAP
    server. but how can i get all the users in my program
    from weblogic server instead of LDAP server?
    BTW,how to configure a RDBMSAuthenticator and what should i do
    in Oracle? which tables should i create? and how are their architectures?
    Thanks
    Daniel

    BTW, i use weblogic platform 8.1
    "Daniel" <[email protected]> дÈëÓʼþ
    news:[email protected]..
    how can i get all the users from weblogic server?
    i have configurated a LDAP server using iPlanet and
    in weblogic server console i see those users from LDAP
    server. but how can i get all the users in my program
    from weblogic server instead of LDAP server?
    BTW,how to configure a RDBMSAuthenticator and what should i do
    in Oracle? which tables should i create? and how are their architectures?
    Thanks
    Daniel

  • How to get input from card reader

    hi, everyone,
    I have a project, which needs me to get input from card reader. My terminal input is IBM POS system, but it didnot provide the API to get the input. How can I get the input? Need your help so much! and thanks a lot

    Now this is a wild idea.... how about searching the IBM site for technical information ?

  • JComboBox    How to get input from JComboBox

    Hi all.
    I have a JComboBox called combobox.
    User can choose one string out of 5 using this JComboBox.
    Whenever the user press a button, I'd like to get an input through this combobox using actionListener.
    How can I get input through JComboBox?
    combobox.getValue() ???
    I appreciate your help !

    http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/JComboBox.html
    Object getSelectedItem()

  • RMI that ask input from user..

    i've been trying to understand the programming for 2weeks!!but still i cant figure out how to get input from client and server process the input and return it to the client.
    can somebody PLEASEEEEE give me a complete simple program that got all the interfaces,client,server and implementation RMI code.Please give me a complete code that i can run that does this:-
    1st-server ask client for input of two numbers.
    2nd-the client give 2 input
    3rd-server compute the number and return it to the client
    i am so lost on how to implement the io in RMI.The program that im supposed to build is much more complicated than this,but right now,i just need to know how the heck to use the input output thing in RMI.

    1st-server ask client for input of two numbers.No. Incorrect design. The client should do that. The server has no interface with the user at the client.
    2nd-the client give 2 inputIf the client does (1) this is unnecessary.
    3rd-server compute the number and return it to the client1. Design the remote interface.
    2. Implement the remote class, extending UnicastRemoteObject, implementing the remote interface, and providing a method that implements the remote method(s).
    3. Write a main() that instantiates the remote object and binds it to the local Registry.
    4. Write a client that does (1) above. Then have it get an instance of the remote interface by looking up the Registry on the server machine, and then have it call the remote method.

Maybe you are looking for

  • I can't connect to a web site via the site's own WiFi.

    This is a strange one. When I'm in the New York Public Library and connected to the internet via their WiFi I can connect to any web site EXCEPT the New York Public Library's! (www.nypl.org) It tries connecting then times out every time. I can connec

  • What is actually happening with getMoreTLAMemory() and native_blocked

    I have an application that seems to periodically lock up and become unresponsive, which we end up killing and restarting. A thread-dump consistently reveals the following scenario: 1) There are many threads (18 or so) with a thread-dump like: "a0-141

  • Infotype Screen control - change field from display to change

    Hello, I have a field in a custom infotype, which is showing up as only display. I want to change it so that values can be input. I checked the screen layout in se51 and found that the field is checked as input possible field. There is no entry for t

  • Increasing size of installation

    I "pacman -Syu"ed today and got some nice info about the update: 100 mb to download and 300 mb to install. Great! But could i find out how much space my arch installation increases by this update? It's not like my installation will be 300 mb bigger a

  • My ipod will only register with itunes after restarting my laptop, after that it just charges.

    I just got a new Lenovo laptop.  When I plug my ipod in, it only registers with iTunes right after the computer has been turned on or restarted.  After that the ipod just charges.  I can find the ipod listed when I go to my control panel and click on