سؤال

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");
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top