hai, i just need to implement a loop that can be stop when i enter "nothing"
by using the following incorrect statement:
BufferedReader br=new BufferedReader(new InputStreamReader (System.in));
do{
System.out.print("Enter any string: ");
String temp;
temp=br.readLine();
}while (br.readLine()!=null);
//this loop is working wrongly,it doesn't stop!
output suppose to be like below:
Enter any string: abc
Enter any string: cds
Enter any string:
//when nothing(empty string) is being enter, the loop stop.
how the above coding can be modified?
1. to provide an exit string (in my example "exit")
2. to implement a Timer which will count for an noumber of seconds and if nothing happends, force the exit from loop.
1.
import java.io.*;
public class x {
public static void main(String[] args) {
BufferedReader br=new BufferedReader(new InputStreamReader (System.in));
try {
String line = null;
System.out.print("Enter any string : ");
while((line = br.readLine()) != null) {
System.out.println("Entere
if(line.equalsIgnoreCase("
break;
System.out.print("Enter any string : ");
}
} catch(Exception e) {System.out.println(e.toSt
}
}