-1

What is a Java equivalent for this C++ code snippet:

string str ;
while(cin>>str){
   //code
}
Roman C
  • 49,761
  • 33
  • 66
  • 176
Gandalf
  • 2,921
  • 5
  • 31
  • 44

4 Answers4

2

Something like this

String str ; 
while((str = System.in.readLine()) != null){
   //code
}
Roman C
  • 49,761
  • 33
  • 66
  • 176
0
Scanner scanner = new Scanner(System.in);
String sentence = scanner.nextLine();
LynAs
  • 6,407
  • 14
  • 48
  • 83
0
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
}
Kick
  • 4,823
  • 3
  • 22
  • 29
-1

you can do it either with a GUI style .

import javax.swing.JOptionPane;
String Input=JOptionPane.showInputDialog("Title","Message");
Mr-Eyes
  • 27
  • 1
  • 6