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 Beginnersreadline 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 Beginnersreadline 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 errorStruts
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 - StrutsStruts
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 - Strutsstruts
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
errorerror 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
errorerror i have 404
error in my program plz tell me yhe solution about
errorerror 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
errorerror 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
ErrorError 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
errorerror 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
errorerror 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
ErrorError 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
ErrorError 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
ErrorError 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
ErrorError 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 Struts 2 Url ValidatorStruts
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 2new
2 <%@page import="java.util.ArrayList"%>
<%@page...;
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
2
sevelet
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
2
import java.io.IOException;
import java.io.PrintWriter;
import
use is of 2use 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 2Magicbox
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 2Struts
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 2Struts
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 2FireFox
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 2Thunderbird
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