readline Error 2

readline Error 2

Hi sir,
can you look again please.
The error is hard to notice, but if you execute the code,
1. enter a string the first input request (eg hello world),
2. ENTER

3a. ENTER n for the next input request
The code will not terminated after the 'n'. This is because the first char is missing and from the readLine(). You would have to to enter 'nn'
for the code to exit. I think the problem is caused by the read() statement, just don't know why.

3b. ENTER another string for the next input request (eg bye world)
The code will output text "ye world", again the first char (b) is missing.

Could you please check again. I have to use the System.in.read() for this home work.

Thanks for the quick response
thanks sella
View Answers

April 27, 2010 at 5:21 PM

Hi Friend,

Use br.readLine instead of System.in.read, your code will work.

Your modified code:

import java.io.*;
class TestAdvt{
public static void main (String[] args){
boolean done=false;
while (!done){
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String str = null;
try{
System.out.println ("Please enter the advertisement message to be displayed (enter 'n' to exit)");
str = br.readLine();
if (!str.equalsIgnoreCase("n")){
System.out.println ("str1 = " + str);
Thread advt = new Thread(new Advertisement(str));
advt.start();
br.readLine();
advt.interrupt();
}
else{
System.out.println ("str2 = " + str);
done = true;
}
}
catch (IOException e){
System.out.println("IOException caught: " + e.getMessage());
}
}
}
}
class Advertisement extends Thread{
private String message;
Advertisement (String message) { this.message=message;}
public void run(){
while (!message.equals("")){
try{
System.out.print(message+".. ");
Thread.sleep(1000);
}
catch (InterruptedException e){
this.message="";
break;
}
}
}
}

Thanks









Related Tutorials/Questions & Answers:
readline Error 2 - Java Beginners
readline Error 2  Hi sir, can you look again please. The error... request (eg hello world), 2. ENTER 3a. ENTER n for the next input request... is missing and from the readLine(). You would have to to enter 'nn' for the code
readline Error - Java Beginners
readline Error  Hi sir, please helpme with my code. Mycode does not work. The readLine () method seems to loose the first character of the string...; Hi Friend, Your code works fine here. Thanks  The error
Advertisements
Struts 2 File Upload error
Struts 2 File Upload error  Hi! I am trying implement a file upload using Struts 2, I use this article, but now the server response the error: ognl.MethodFailedException: Method "setArquivo" failed for object
ModuleNotFoundError: No module named 'readline'
library, ModuleNotFoundError: No module named 'readline' error...ModuleNotFoundError: No module named 'readline'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named
Struts 2 : Http Status Error 404 - Struts
Struts 2 : Http Status Error 404  Hi All, I'm facing the below... error as shown below. see below error for the details code... --------------------------------------------------------------------------- ERROR(404) : "The requested
struts 2 Application starting error - Struts
struts 2 Application starting error  Hello Sir/Madam, Recently i have installed tomcat 5.5.23 on my window machine with XP, then i make an small application which i have attached with name Struts2Application, but after
ModuleNotFoundError: No module named 'micropython-readline'
: No module named 'micropython-readline' error? Thanks   Hi..., ModuleNotFoundError: No module named 'micropython-readline' error...ModuleNotFoundError: No module named 'micropython-readline'  Hi
ModuleNotFoundError: No module named 'micropython-readline'
: No module named 'micropython-readline' error? Thanks   Hi..., ModuleNotFoundError: No module named 'micropython-readline' error...ModuleNotFoundError: No module named 'micropython-readline'  Hi
ModuleNotFoundError: No module named 'micropython-readline'
: No module named 'micropython-readline' error? Thanks   Hi..., ModuleNotFoundError: No module named 'micropython-readline' error...ModuleNotFoundError: No module named 'micropython-readline'  Hi
ModuleNotFoundError: No module named 'pycopy-readline'
'pycopy-readline' error? Thanks   Hi, In your python... named 'pycopy-readline' error will be solved. Thanks...ModuleNotFoundError: No module named 'pycopy-readline'  Hi, My
ModuleNotFoundError: No module named 'urwid-readline'
'urwid-readline' error? Thanks   Hi, In your python... 'urwid-readline' error will be solved. Thanks...ModuleNotFoundError: No module named 'urwid-readline'  Hi, My
HTTP Status 404 - /web/login/showLogin.action Error in Struts 2 - Struts
HTTP Status 404 - /web/login/showLogin.action Error in Struts 2  Hi... Eclipse 3.4 Struts 2 Now my question is I am trying to implement the login... the doLogin action . when I click on the link I get the following error type Status
Version of rubygems>jruby-readline dependency
List of Version of rubygems>jruby-readline dependency
Maven Repository/Dependency: rubygems | jruby-readline
Maven Repository/Dependency of Group ID rubygems and Artifact ID jruby-readline. Latest version of rubygems:jruby-readline dependencies... 10 Aug 2016 2 1.2.1 10 Aug 2016
this code gives addition of 2 numbers in j2me..but the code is not executing ..can u pls find out the error...??
this code gives addition of 2 numbers in j2me..but the code is not executing ..can u pls find out the error...??  import javax.microedition.midlet.*; import javax.microedition.lcdui.*; public class add1 extends MIDlet implements
Maven Dependency jruby-readline >> 1.1.1
You should include the dependency code given in this page to add Maven Dependency of rubygems >> jruby-readline version1.1.1 in your project
Maven Dependency jruby-readline >> 1.0
You should include the dependency code given in this page to add Maven Dependency of rubygems >> jruby-readline version1.0 in your project
Maven Dependency jruby-readline >> 1.1.0
You should include the dependency code given in this page to add Maven Dependency of rubygems >> jruby-readline version1.1.0 in your project
error
error  while iam compiling iam getting expected error
Error-
Error-   Hello, I would like to know about XSD file. I try to print XML file but I am getting error SAXException-- says Content is not allowed in prolog. Please help me
error
error  i have 404 error in my program plz tell me yhe solution about
error
error  i have 404 error in my program plz tell me yhe solution about
error
/ServletUserEnquiryForm.shtml getting an error given below SQLException caught: [Microsoft][ODBC SQL Server Driver]COUNT field incorrect or syntax error please suggest
error
error  whats the error.............. import java.util.Scanner...(); switch(a) { case 1:add(); break; case 2:sub(); break...."); System.out.println("2 For Subtract."); a=s.nextInt(); switch(a) { case
Error
Error  I have created ajax with php for state and city. When I change state then city will not come in dropdown list and it give me error as 'Unknown Runtime Error'. This error come only in IE browser, but in other brower
error
error  java.lang.unsupportedclassversionerror:bad major version at offset 6 how to solve this????   Hi, Please check the version of framework used and also the JDK version.ADS_TO_REPLACE_1 This type error also comes
error
error
error
error  When I deploye the example I have this message cannot Deploy HelloWorld Deployment Error for module: HelloWorld: Error occurred during deployment: Exception while deploying the app [HelloWorld
error!!!!!!!!!
error!!!!!!!!!   st=con.createStatement(); int a=Integer.parseInt(txttrno.getText()); String b=txttname.getText(); String c=txtfrom.getText(); String d=txtto.getText
error!!!!!!!!!
error!!!!!!!!!   st=con.createStatement(); int a=Integer.parseInt(txttrno.getText()); String b=txttname.getText(); String c=txtfrom.getText(); String d=txtto.getText
error!!!!!!!!!
error!!!!!!!!!   st=con.createStatement(); int a=Integer.parseInt(txttrno.getText()); String b=txttname.getText(); String c=txtfrom.getText(); String d=txtto.getText
Error
Error  Hi. I am getting error in the following code after the line I have commented as ERROR. How to solve this. Thanks in advance. package...;"); // ERROR out.println(" var pattern
Error
Error  Hi. I am getting error in the following code after the line I have commented as ERROR. How to solve this. Thanks in advance. package...;"); // ERROR out.println(" var pattern
Error
Error  Hi. I am getting error in the following code after the line I have commented as ERROR. How to solve this. Thanks in advance. package...;"); // ERROR out.println(" var pattern
Error
Error  Hi. I am getting error in the following code after the line I have commented as ERROR. How to solve this. Thanks in advance. package...;"); // ERROR out.println(" var pattern = /^\d{3,5
error
"+it); } } this is my program i am getting an error saying cannot find symbol class stringADS
error
is"+sum); } } this is my program i need to print the series (1+2/12)+(1+2
Maven dependency for rubygems - jruby-readline version 1.2.1 is released. Learn to use jruby-readline version 1.2.1 in Maven based Java projects
Maven dependency for  rubygems  - Version 1.2.1 of jruby-readline released The developers of   rubygems - jruby-readline project have... of  rubygems - jruby-readline library is 1.2.1. Developer can use
Maven dependency for rubygems - jruby-readline version 1.2.0 is released. Learn to use jruby-readline version 1.2.0 in Maven based Java projects
Maven dependency for  rubygems  - Version 1.2.0 of jruby-readline released The developers of   rubygems - jruby-readline project have... of  rubygems - jruby-readline library is 1.2.0. Developer can use
ReadLine(String fmt,Object... args) of Console class - Java Beginners
ReadLine(String fmt,Object... args) of Console class  How to reload... = System.console(); if(console != null) { String formatString = "%1$4s %2$10s...;, "100"); console.printf(formatString, "2", "20"
Struts 2 Url Validator
Struts 2 Url Validator       The URLValidator of Struts 2 Framework checks whether the String contained within..., it generates an error message.  The error message is supplied between
new 2
new 2  <%@page import="java.util.ArrayList"%> <%@page...; @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@2 sevelet @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@2 import java.io.IOException; import java.io.PrintWriter; import
use is of 2
use is of 2  why we use 2 in "Integer.parseInt(str,2);" for binary to decimal conversion..??   ya i got it... because binary contain only two o and 1...so here use 2...same as octal has 8
Magicbox 2
Magicbox 2  how to build this? import java.util.*; class magicbox...; } } } } v15=a[0][0]+a[0][1]+a[0][2]==15 && a[1][0]+a[1][1]+a[1][2]==15 && a[2][0]+a[2][1]+a[2][2]==15 &&
Struts 2
Struts 2  we can extend DispatchAction class to implement a common session validation in struts 1.x. how to do the same in the struts2
Struts 2
Struts 2   I am just new to struts 2 and need to do the task. I have a requirement like this : when i click on link like Customer , this will display all the customers , address from a database table using jdbc and the screen
Struts 2
Struts 2  I am getting the following error.pls help me out. The Struts dispatcher cannot be found. This is usually caused by using Struts tags without the associated filter. Struts tags are only usable when the request has
Echo 2
Echo 2       Echo 2 allows you to code Ajax apps in pure Java (Demo)which automatically generates HTML and Javascript. Read full DescriptionADS_TO_REPLACE_1
FireFox 2
FireFox 2       The award... to do on the Web, and Firefox 2 is full of helpful features to make your... Add-ons that enhance Firefox. It?s easy to personalize Firefox 2
Thunderbird 2
Thunderbird 2       Mozilla?s Thunderbird 2 email application is more powerful than ever. It?s now... Information Organized Thunderbird 2 features many new enhancements to help

Ads