Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > Java Basics
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old March 11th, 2018, 07:14 PM
Registered User
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:

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.
Old March 20th, 2018, 08:59 PM
Registered User
Join Date: Mar 2018
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts

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.


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 04:37 PM
capturing printing settings when printing reports nikolaosk Access VBA 0 February 8th, 2005 04:14 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.