Domanda

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

string str ;
while(cin>>str){
   //code
}

Nessuna soluzione corretta

Altri suggerimenti

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");
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top