java - Dialog Box Input/Output assistance -


the question is: write program prompts user input number. program should output number , message whether number positive or negative or zeros.

what have far this:

import javax.swing.joptionpane; import java.util.*;  public class problem1 {   public static void main(string[] args) {     scanner scan = new scanner(system.in);     string str;     int num;      str = joptionpane.showinputdialog("enter number ");      num = scan.nextint();     str = "the number " + num;      if (num >= 1)         joptionpane.showmessagedialog(null, str, "you have entered positive integer", joptionpane.plain_message);     else if (num <= -1)         joptionpane.showmessagedialog(null, str, "you have entered negative integer", joptionpane.plain_message);     else         joptionpane.showmessagedialog(null, str, "you have entered zero", joptionpane.plain_message);      system.exit(0);   } } 

i can input number can't see end result. please me problem.

the line

num = scan.nextint(); 

due earlier line

scanner scan = new scanner(system.in); 

scans standard input , waits there. want scan str. correct code this:

str = joptionpane.showinputdialog("enter number "); scanner scan = new scanner(str); num = scan.nextint(); 

Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -