program help

Discussion in 'Java' started by taurus, Dec 3, 2006.

Thread Status:
Not open for further replies.
  1. taurus

    taurus New Member

    Joined:
    Dec 3, 2006
    Messages:
    11
    Likes Received:
    0
    Trophy Points:
    0
    Code:
    import javax.swing.*;
    public class test
    {
        public static void main(String[] args)
        {
            String input;
            int integer, total, another;
            do
            {
                input = JOptionPane.showInputDialog(null, "Enter a positive integer");
                integer = Integer.parseInt(input);
                while (isPositive(integer));
                {
                input = JOptionPane.showInputDialog(null, "Enter a positive integer");
                }
                total = addNumbers(integer); 
                JOptionPane.showMessageDialog(null,"The total of integers between  1 and " + integer + " is " + total);
                another = JOptionPane.showConfirmDialog(null, "Do you want to continue");
            }
            while (another == JOptionPane.YES_OPTION);
        }
    
    public static boolean isPositive(int integer)
        {
            while(integer <= 0)
            {
            return true;
            }
            return false;
        }
    public static int addNumbers(int integer)
        {
            int total = 0, count = 0;
            while(count < integer)
            {
                count = count + 1;
                total = total + count;
            }
            return total;
        }
    }
    
    
    Now i got a problem, u c my boolean method, well what i want to say is when its not a positive number then it should re prompt the user for a number(input = JOptionPane.showInputDialog(null, "Enter a positive integer")

    But right now its not workin correctly. it always does it in a way
    can someone just help me wit that?
    thanx
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
Thread Status:
Not open for further replies.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice