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
Post a Comment