I have a Scanner
and i am getting day of the week from console then i want to show day in JOptionPane.showMessageDialog
method but its not working.
public class TestClass {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String day = scan.nextLine();
JOptionPane.showMessageDialog(null, day);
}
}
what is wrong?
thanks in advance.
Not sure if this helps, but I could find no issue with your code. Sharing what I've tried and maybe that'll help you debug your issue.
package simple.concepts.com;
import java.util.Scanner;
import javax.swing.JOptionPane;
public class Test {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("Enter day");
String day = scan.nextLine();
JOptionPane.showMessageDialog(null, day);
scan.close();
}
}
While giving the input :
Enter day : Monday
(Press enter)
You should be seeing the pop-up with 'Monday'
EDIT:
Try running eclipse with administration rights. Restart and run again. Also run the program once and minimize all the windows, you should see it. It constantly takes input until and unless you close the pop-up.