How to detect the "enter" key is pressed in my console program

Posted on 2006-05-16
Last Modified: 2012-05-05
Hi Friends,
I have a loop in my program that asks the user to enter a number,I want that if the user presses the 'enter' key instead of entering any number,then the loop should exit.
But I don't know how to detect the 'enter' key as I am not using any GUI or ActionListener classes,is there some ASCII code for the enter key,that I can read and exit the loop.
Please help.
Question by:harmeek_80
    1 Comment
    LVL 92

    Accepted Solution

    assuming you're using readLine() to red the input you would check for an empty string

    String input = stdin.readLine();
    if (input.length()==0)
       // <return> entered

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
    Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
    Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
    This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

    794 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

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now