Results 1 to 2 of 2
  1. #1
    csanch11 is offline Member
    Join Date
    Oct 2013
    Posts
    47
    Rep Power
    0

    Default Adding all the numbers together in Netbeans

    My intention is for the user to input 9 numbers and then have the program add all those numbers together. Sadly the program only allows the user to enter 9 numbers but does nothing to them. Here's what I have so far.... Anyone know how to fix this

    package pkg9numbers;

    import java.util.Scanner;

    /**
    * Author: Your Name Here Date: Assignment:
    */
    public class Main {

    public static void main(String[] args) {
    // variable declarations (and most initializations) {
    Scanner keys = new Scanner(System.in);
    // now the program logic ...
    int sum = 0;
    int n = 9;
    int i = 0;
    while (i < n) {
    System.out.print("A number please. ");
    int input = keys.nextInt();
    input = input + sum; //Add all the 9 numbers together
    i++;
    }
    } // end of main() method
    } // end of Main class

  2. #2
    jcbm is offline Member
    Join Date
    Dec 2013
    Posts
    2
    Rep Power
    0

    Default Re: Adding all the numbers together in Netbeans

    input = input + sum is definitely not right. What you want is sum = sum + input

Similar Threads

  1. Adding odd numbers
    By kmlam585 in forum New To Java
    Replies: 6
    Last Post: 02-12-2012, 11:25 PM
  2. adding numbers in a string?
    By brycepower1 in forum New To Java
    Replies: 14
    Last Post: 08-19-2011, 06:39 PM
  3. adding numbers
    By droidus in forum New To Java
    Replies: 7
    Last Post: 03-09-2011, 05:26 AM
  4. adding numbers in an array together
    By pds8475 in forum New To Java
    Replies: 3
    Last Post: 01-22-2011, 08:23 PM
  5. Adding numbers in an array?
    By hawaiifiver in forum New To Java
    Replies: 9
    Last Post: 01-22-2009, 04:50 AM

Posting Permissions

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