Link to home
Start Free TrialLog in
Avatar of AgentC4
AgentC4

asked on

Sum Of Numbers

Im trying to write a program that asks the user for a positive nonzero integer value. The program should use a loop to get the sum of all the integers from 1 up to the number entered. For example, if the user entered a 50, the loop will find the sum of 1,2,3,4,....50.

i think the code i posted may be wrong but ive spent hours trying to figure it out and my teacher isnt helpful at all. :(

i really would appreciate it if a full solution code is posted. This will help me study for my other programs im having trouble with.
public class SumOfNumbers
{
        public static void main( String [] args)
        {
                
            double nonZero;
            double numbers;
            double totalNumbers;
            String input;
                
        
            for( int count = 1; count <= nonZero; count++ )
            {
                input = JOptionPane.showInputDialog(null, "Please enter a nonzero positive integer.");
 
              nonZero = Double.parseDouble(input);
 
            }   
                
            JOptionPane.showMessageDialog(null, "The sum of the integers is: " + nonZero);
        }
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Opalelement
Opalelement

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of AgentC4
AgentC4

ASKER

You're a life saver, thank you so much yes this works perfectly. ill definitely study it and work more and do examples.