Scanner & Message Box

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Mar 2007
Posts: 68
Reputation: Derice is an unknown quantity at this point 
Solved Threads: 1
Derice Derice is offline Offline
Junior Poster in Training

Scanner & Message Box

 
0
  #1
Feb 8th, 2008
I am have no idea wat is wrong with my code. The system is supposed to get 3 inputs from users and display a message box to show the number in ascending order. If i were to get input from input box and display it in message box it will work perfectly but when i tried to modify it where the input were taken from scanner and display it in message box. The program just stopped when i entered the 3rd integer. Any1 can give me some idea wat is wrong? Here is my code:

  1. import java.util.Scanner;
  2. import javax.swing.JOptionPane;
  3.  
  4. class lab3q2
  5. {
  6. public static void main(String[] args)
  7. {
  8.  
  9. Scanner abc = new Scanner(System.in);
  10.  
  11. System.out.print("Enter 3 integers\nfirst integer: ");
  12. int int1 = abc.nextInt();
  13. System.out.print("\nSecond integer: ");
  14. int int2 = abc.nextInt();
  15. System.out.print("\nThird integer: ");
  16. int int3 = abc.nextInt();
  17.  
  18. int min, med, max;
  19.  
  20. if(int1 > int2)
  21. {
  22. med = int1;
  23. min = int2;
  24. }
  25. else
  26. {
  27. med = int2;
  28. min = int1;
  29. }
  30.  
  31. if(int3 > med)
  32. {
  33. max = int3;
  34. }
  35. else
  36. {
  37. max = med;
  38. med = int3;
  39. }
  40.  
  41. JOptionPane.showMessageDialog(null,"The sorted number are "+min+" "+med+" "+max, "SimpleSortingOutput",JOptionPane.INFORMATION_MESSAGE);
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 1,681
Reputation: javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all 
Solved Threads: 227
Featured Poster
javaAddict's Avatar
javaAddict javaAddict is offline Offline
Posting Virtuoso

Re: Scanner & Message Box

 
0
  #2
Feb 9th, 2008
Try adding a System.out.println(); before the JOptionPane to see where the program stops
Check out my New Bike at my Public Profile at the "About Me" tab
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 68
Reputation: Derice is an unknown quantity at this point 
Solved Threads: 1
Derice Derice is offline Offline
Junior Poster in Training

Re: Scanner & Message Box

 
0
  #3
Feb 9th, 2008
sorry, i made a mistake. The command window overlapped the message box. It actually working.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC