Wrox Programmer Forums
|
J2EE General J2EE (Java 2 Enterprise Edition) discussions. Questions not specific to EE will be redirected elsewhere.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the J2EE 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 August 21st, 2005, 04:32 PM
Registered User
 
Join Date: Aug 2005
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default array test 5

 when i run my program this message appears "Exception in thread "main" java.lang.NoClassDeFoundError: org/javadevices/javaclass/ArrayTest5



//The purpose of this program is to demonstrate the use of some simple arrays.

//This package command is more like what one would expect to find when dealing with
// Java applications or libraries that are meant to be widely used.
package org.javadevices.javaclass;


public class ArrayTest5
{

  public ArrayTest5()
  {
    super();
  }//end constructor


  //This method accepts a String array which contains tool names and and an
  // integer array which contains the weight in grams for these tools. Each
  // tool name is then printed to standard out along with its weight and the
  // number of characters in its name.
  public void printTools(String[] pTools, int[] tWeights)
  {
    int[] toolsLetterCount = getLetterCount(pTools);

    int arrayLength = pTools.length;

    for (int x = 0; x < arrayLength; x++)
    {
      System.out.println(pTools[x] + " - " + tWeights[x] + " grams - " + toolsLetterCount[x] + " letters");
    }// end for

  }//end method


  //This method accepts a String array and it returns a new integer array
  // which contains the letter count for each word in the String array.
  public int[] getLetterCount(String[] words)
  {

    //Create a new empty integer array which has the same number of members
    // as the String array that was passed into this method.
    int[] letterCount = new int[words.length];

    int x = 0;
    while (x < words.length)
    {
      letterCount[x] = words[x].length();
      x++;
    }//end while

    return letterCount;
  }//end method



  public static void main(String[] args)
  {
    ArrayTest5 at = new ArrayTest5();

    //Create a reference of type "String array" called 'tools' and then also
    // create a new String array object and have 'tools' refer to it. Notice that
    // an array can be initialized when it is created by placing the array
    // members in braces.
    String[] tools = new String[] {"hammer", "wrench", "screwdriver", "hacksaw", "pliers"};

    //Create a reference of type "int array" called 'toolWeights' and then
    // also create a new int array object and have 'toolWeights' refer to it.
    // Notice that an array can be initialized when it is created by
    // placing the array members in braces.
    int[] toolWeights = new int[] {510,102,105,331,233};

    at.printTools(tools, toolWeights);

  }//end main

}//end class







Similar Threads
Thread Thread Starter Forum Replies Last Post
Convering a String Array to an Integer array nkrust C# 9 November 17th, 2010 12:02 PM
Go from 2d Array to 1d array without defining type OneQuestion General .NET 1 January 10th, 2008 11:13 AM
error when sorting an Array of Array nancy VBScript 2 February 17th, 2005 12:57 PM
Passing php array values to javascript array gkrishna Pro PHP 0 November 6th, 2004 03:20 AM
How do I test for an empty array element kmoran Excel VBA 1 October 8th, 2004 03:34 AM





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