What am i missing or doing wrong

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Austinwhite1995
    New Member
    • Sep 2016
    • 1

    What am i missing or doing wrong

    // 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+".");
    }
    }
  • Oralloy
    Recognized Expert Contributor
    • Jun 2010
    • 988

    #2
    Austinwhite1995 ,

    When you post code, please include it in [CODE] blocks, so it remains formatted.

    We do not mind helping you learn our craft, so please do your best to make it easy to understand your problems.

    Just quickly reading your code, I see that you are accessing an object keyboard. Where is this coming from? Did you leave out an import static declaration that gives you access to the object?

    Since this won't work, can you back up to one of your tests that had some useful results? That might be a better starting point to work from.

    If you are completely lost, please tell us, and we will try to help you get back on track and up to speed. The first few steps are hard, and it seems that you might be a little lost.

    Comment

    Working...