Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Java > Java and JDK > Java Basics
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Java Basics General beginning Java language questions that don't fit in one of the more specific forums. Please specify what version.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Java Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old March 11th, 2018, 08:14 PM
Registered User
Points: 5, Level: 1
Points: 5, Level: 1 Points: 5, Level: 1 Points: 5, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Feb 2018
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Printing multiples of 13 using array

Hi, I'm new. I'm trying to use an array to print out multiples of 13, up to 400. (I know 400 isn't one of them.) All my computer prints out are zeros.

Here's my code:

Code:
 
class multiples {
    public static void main(String[] argumets){
        int mults [] = new int [400];
        
        for  (int dex = 0; dex < mults.length; dex++){
            int current = mults[dex];
            if (current % 13 == 0){
                System.out.println("#: " + current);
            }
        }
    }
}
Can someone tell me why it only prints zeros? Thanks in advance.
Reply With Quote
  #2 (permalink)  
Old March 20th, 2018, 09:59 PM
Registered User
Points: 3, Level: 1
Points: 3, Level: 1 Points: 3, Level: 1 Points: 3, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2018
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi dTech,

You are mixing the concept of the array element index with the array element value.
The array mults has been created with capacity of 400 elements but all elements have been initialized to 0.
Your code simply is trying to pick the element values at index 13, 2*13,3*13,..and so on up to but excluding index 400. But the element values are already 0s.

Thanks,
--Wasadeh
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
List of node values, only once for multiples mphare XSLT 4 February 1st, 2008 03:09 PM
Go from 2d Array to 1d array without defining type OneQuestion General .NET 1 January 10th, 2008 11:13 AM
find multiples stealthdevil Access VBA 4 March 6th, 2007 11:26 AM
Getting Array Error message with Begin PHP4 Ch 13 vaderj PHP Databases 4 April 17th, 2005 05:37 PM
capturing printing settings when printing reports nikolaosk Access VBA 0 February 8th, 2005 04:14 AM



All times are GMT -4. The time now is 12:37 PM.


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.