What is a Java equivalent for this C++ code snippet:
string str ;
while(cin>>str){
//code
}
What is a Java equivalent for this C++ code snippet:
string str ;
while(cin>>str){
//code
}
Something like this
String str ;
while((str = System.in.readLine()) != null){
//code
}
Scanner scanner = new Scanner(System.in);
String sentence = scanner.nextLine();
Scanner scanner = new Scanner(System.in);
boolean flag = true;
while(flag)
{
String str = scanner.nextLine();
// Add any condition to set flag = false to exit from while loop
}
you can do it either with a GUI style .
import javax.swing.JOptionPane;
String Input=JOptionPane.showInputDialog("Title","Message");