?
Solved

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

Posted on 2006-05-16
1
Medium Priority
?
258 Views
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.
0
Comment
Question by:harmeek_80
1 Comment
 
LVL 92

Accepted Solution

by:
objects earned 200 total points
ID: 16695782
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
}
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month13 days, 11 hours left to enroll

755 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