Results 1 to 4 of 4
  1. #1
    keycoffee is offline Member
    Join Date
    Jan 2010
    Posts
    9
    Rep Power
    0

    Default need help! assignment due by tmr!

    Hi. I need help for this program.

    import javax.swing.JOptionPane;


    public class Homework3
    {

    public static void main(String args[]){

    int number;
    String message1 = "Please enter the positive number"+ "\n";
    String message2 = "Please enter the positive number, not negative number"+ "\n";
    String message3 = "Please enter in numbers, not letters"+ "\n";
    String num, outputMessage ;

    try{
    num = JOptionPane.showInputDialog(message1);
    number = Integer.parseInt(num);

    if (number<0)
    throw new IllegalArgumentException();
    outputMessage = "The number was"+ number ;
    JOptionPane.showMessageDialog(null,outputMessage);
    }

    catch( NumberFormatException e)
    {
    JOptionPane.showMessageDialog(null,message3);
    }

    catch ( IllegalArgumentException e)
    {
    JOptionPane.showMessageDialog(null,message2);
    }

    System.exit(0);

    }
    }

    So far its working but I want the Input to arrange in positive integer in range of 0 to 9999. It accepts the 4 digits of positive integer. and also once I put the positive integer in Input, the output has to be showing in this way.

    The number was 1234
    The digits are
    1
    2
    3
    4

    How to write this program? please help me!!!!!!!

  2. #2
    [RaIdEn] is offline Senior Member
    Join Date
    Oct 2009
    Location
    California,US
    Posts
    201
    Rep Power
    6

    Default

    1st usually doesnt encourage homework solutions. but atleast i'll try to help.

    try adding the elements into an array, and then print it out using a for loop.

    shldnt be too hard :)

  3. #3
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default

    I won't help people reposting the same question over and over.
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Agree. Don't keep reposting the same question. I've locked the other thread.

Similar Threads

  1. Need with my assignment ...
    By allergy01 in forum New To Java
    Replies: 1
    Last Post: 04-25-2009, 09:33 AM
  2. I am looking for help with an assignment
    By nanoo51969 in forum New To Java
    Replies: 1
    Last Post: 03-23-2009, 10:41 PM
  3. GUI First Assignment-DUE 8/1/08
    By ljk8950 in forum AWT / Swing
    Replies: 2
    Last Post: 08-01-2008, 05:23 AM
  4. First GUI Assignment
    By ljk8950 in forum New To Java
    Replies: 1
    Last Post: 07-31-2008, 08:29 AM
  5. for Assignment plz help
    By assamhammad in forum New To Java
    Replies: 1
    Last Post: 11-06-2007, 09:35 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •