-1

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

string str ;
while(cin>>str){
   //code
}
Roman C
  • 48,723
  • 33
  • 63
  • 158
Cid
  • 2,466
  • 4
  • 24
  • 36

4 Answers4

2

Something like this

String str ; 
while((str = System.in.readLine()) != null){
   //code
}
Roman C
  • 48,723
  • 33
  • 63
  • 158
0
Scanner scanner = new Scanner(System.in);
String sentence = scanner.nextLine();
LynAs
  • 5,999
  • 12
  • 44
  • 81
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,742
  • 2
  • 20
  • 25
-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