// can anyone help me find out what im doing wrong. ive spent my free time in my last couple days working on these and im now behind in my class and am afraid of getting lost in the subjects. the point of this assignment is to find the sum of all numbers from 1 to the number given by the operator. thank you for your time so much and have a good day
import java.util.Scann er;
public class SumofNumbers
{
public static void main(String[] args)
{ //state/declare variables
//String input;
int Input=0;
int Number=0;
int sum=0;
//ask for input
System.out.prin t("Enter a positive non decimal number you would like to know the sum of all the numbers from 1 to that number. * Must be larger than 0* ");
Input= keyboard.nextLi ne;
//start loop
while (Input<= 0)
{
System.out.prin t("Enter a number that is positive and not decimal");
}
while (Number <= Input)
{
++Number;
sum = Number + sum;
}
//show result
System.out.prin t("The sum of Numbers from one to "+Input+" is "+sum+".");
}
}
import java.util.Scann er;
public class SumofNumbers
{
public static void main(String[] args)
{ //state/declare variables
//String input;
int Input=0;
int Number=0;
int sum=0;
//ask for input
System.out.prin t("Enter a positive non decimal number you would like to know the sum of all the numbers from 1 to that number. * Must be larger than 0* ");
Input= keyboard.nextLi ne;
//start loop
while (Input<= 0)
{
System.out.prin t("Enter a number that is positive and not decimal");
}
while (Number <= Input)
{
++Number;
sum = Number + sum;
}
//show result
System.out.prin t("The sum of Numbers from one to "+Input+" is "+sum+".");
}
}
Comment