Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Sep 2009
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Problem regarding Arrays

    Hey, I'm working on a problem and what I need the program to do is to add up the numbers in the array NOT add up how many numbers there are. There are 5 total numbers that a user will input. The counting of the numbers will be in a seperate method which will then return to the main. Then be displayed through system.out.println. I don't know where I am going wrong any help? Thanks!

    Code:
     
    import javax.swing.*;
    import java.util.*;
    public class Question10 {
    
    public static void main (String []args) {
    
    //declares
    Scanner keyboard = new Scanner(System.in);
    
    int [] myNums = new int[5];
    for (int i=0; i < myNums.length; i++) {
    System.out.println ("Please Enter Data");
     myNums[i]= keyboard.nextInt();
    }
    
    
    
    
    } //end main
    
    
    public static int getTotal(int inArray) {
    
    int a,b,c,d,e,f;
    f = a+b+c+d+e;
    
    return f;
    }
    
    }//end class

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,068
    Thanks
    0
    Thanked 256 Times in 252 Posts
    java != javascript

    Ask the mods to move this thread to the appropriate forum.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________


  •  

    Posting Permissions

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